Hi,
I stumbled upon a confusing listreverseiterator behavior:
l = [1, 2, 3, 4]
i = iter(l)
ri = reversed(l)
len(i)
Traceback (most recent call last):
File stdin, line 1, in module
TypeError: object of type 'listiterator' has no len()
len(ri)
4
ri.next()
4
len(ri)
3
This is the only
Unless I'm misconstruing something the problem is that reversed returns two
different object types depending on if it's a list or a tuple
l = [1,2,3,4]
i = iter(l)
ri = reversed(l)
l
[1, 2, 3, 4]
ri
listreverseiterator object at 0x00D5C8F0
i
listiterator object at 0x00D5C3F0
t = (1,2,3,4)
I realized after I fired off my response that this was still bugging me...
it appears that the documentation is incorrect
from 2.1 Built-in Functions (v2.5 in case it matters... a quick search of
bugs doesn't seem to show anything though)
*reversed*( seq) Return a reverse iterator. seq must be
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
From: Armin Ronacher [EMAIL PROTECTED]
len(ri)
4
ri.next()
4
len(ri)
3
This is the only reverse iterator with that sort of behavior.
Use the bug tracker please and assign to me.
At one time, some iterators had the ability to know
their own length and that would change as the
iterator
Jeff Hall schrieb:
I realized after I fired off my response that this was still bugging
me... it appears that the documentation is incorrect
from 2.1 Built-in Functions (v2.5 in case it matters... a quick search
of bugs doesn't seem to show anything though)
*reversed*( seq)