negative indices for sequence types
Martin v. Löwis
martin at v.loewis.de
Sun Sep 7 15:06:51 EDT 2003
danbmil99 at yahoo.com (dan) writes:
> This fact is *deeply* buried in the docs, and is not at all intuitive.
I find it highly intuitive and very convenient.
> If you want this behavior, how hard is it to say a = b[x %
> len(b)] ??
*This* I would call un-intuitive. It is also much slower.
To get the last element, you currently write b[-1]. If that was not
available, you would have to write b[len(b)-1], which is still
significantly slower. Also, you might not have a variable name, so try
rewriting foo()[-1].
Regards,
Martin
More information about the Python-list
mailing list