A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2008-August/082018.html below:

[Python-Dev] Confusing listreverseiterator Behavior

[Python-Dev] Confusing listreverseiterator BehaviorArmin Ronacher armin.ronacher at active-4.com
Tue Aug 26 22:04:03 CEST 2008
Jeff Hall <hall.jeff <at> gmail.com> writes:

> reversed(
> seq)
> Return a reverse iterator. seq must be an object which 
> supports the sequence protocol (the __len__() method and the __getitem__()
method with integer arguments starting at 
> 0). New in version 2.4. the above appears to only be true for lists. For
> tuples and strings it creates a reverse OBJECT which behaves slightly
> differently (notably by not including a len() method as you noticed)
> I can't find how to actually create a "tuplereverseiterator" or
> "stringreverseiterator" objects... nor does there appear to be a way to
> create a "reversed" object from a list...
That's an implementation detail what exactly the reverse iterator is.  The
same applies to iter() calls.  iter("foo") for example returns a iterator
type, iter([]) returns a list iterator.  The thing you quoted above is the
requirement for the object that you pass to reverse(), not the object
returned which is some kind of iterator that happens to iterate over the
sequence in reverse.

The problem I personally have with it is that the listreverseiterator is the
only iterator in the standard library that changes the length during
iteration and that it's the only reverse iterator that has a length.  Even
more stunning as the normal iterator doesn't have one.


Regards,
Armin


More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4