![]() |
|
[Python] Explicit index position values - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] Explicit index position values (/showthread.php?tid=6183412) |
Explicit index position values - simmer - Dec 2, 2021 Is there a way to reference N[-1] without calculating the value of -1? RE: Explicit index position values - Sierra-117 - Dec 2, 2021 If you want the index number of the last index the easiest method is: last_index = len(N) - 1 If you need the element at the last index then just use the negative index: last_element = N[-1] If I misunderstood the question please clarify. RE: Explicit index position values - simmer - Dec 2, 2021 Sorry let me clarify. I have a for loop that counts iterations of natural numbers, so N[set(), set(set()), set(set(set())), ect] I’m trying to reference the last position in this index without actually calling the value of N[-1]… N[1] should be == N[set()] at that point. RE: Explicit index position values - Sierra-117 - Dec 2, 2021 (Dec 2, 2021 12:05 PM)simmer Wrote: Sorry let me clarify. I feel like this isn't the way to approach whatever problem you are trying to solve, you generally want to be able to use N[-1]. Could you give more details about the entire problem you are solving and not the issue you're having? Perhaps there is a better approach. RE: Explicit index position values - simmer - Dec 3, 2021 I’m not sure I understand the difference between an issue I’m having and the problem I’m solving I mean I’m trying to calculate N[float(‘inf’)] to equate it to a formula? What kind of rhetoric are you looking for? |