Is there a way to reference N[-1] without calculating the value of -1?
|
Python
Explicit index position values |
|
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.
Software Engineer for Hire. White-hat only. DM Me.
Dec 2, 2021 12:05 PM
(This post was last modified: Dec 2, 2021 01:50 PM by simmer.)
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. (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.
Software Engineer for Hire. White-hat only. DM Me.
Dec 3, 2021 06:39 AM
(This post was last modified: Dec 3, 2021 08:04 AM by simmer.)
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? |
|
|


