[Python-Dev] Confusing listreverseiterator Behavior

Jeff Hall hall.jeff at gmail.com
Tue Aug 26 21:21:15 CEST 2008


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)
>>> it = iter(t)
>>> rit = reversed(t)
>>> it
<tupleiterator object at 0x00D5C030>
>>> rit
<reversed object at 0x00D5CC90>
>>>

reversing a tuple (or a string) returns a "reversed object"
reversing a list returns a "listreverseiterator"

definitely an inconsistency
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20080826/9b0d71f1/attachment.htm>


More information about the Python-Dev mailing list