You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The use case for getitem(n) with n as a negative number depended on an unlikely combination of circumstances:
you have an iterable that is not a sequence (otherwise, just use s[-n]).
the iterable is somewhat large (otherwise, just list it into memory)
the iterable is finite (otherwise, getitem() dies in a infinite loop)
you only want one entry (otherwise, you'll have make multiple passes)
that entry is located near the end (otherwise getitem() is memory intensive)
you know the entry's offset from the end but not from the beginning
identifying the record of interest depends only on its position, not its content
In the common case where the index is zero, the preferred spelling is to use the next() method -- that is its purpose. For cases where the index is a positive integer, uing islice(it, n).next() suffices though it doesn't have the cute feature for a default value.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: