[Python-Dev] Confusing listreverseiterator Behavior (original) (raw)
Jeff Hall hall.jeff at gmail.com
Tue Aug 26 21:47:13 CEST 2008
- Previous message: [Python-Dev] Confusing listreverseiterator Behavior
- Next message: [Python-Dev] Confusing listreverseiterator Behavior
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 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...
Just tested this s = 'bob' t = (1,2,3,4) l = [1,2,3,4) rs = reversed(s) rt = reversed(t) rl = reversed(l)
type(rs) <type 'reversed'> type(rt) <type 'reversed'> type(rl) <type 'listreverseiterator'> type(rs) == type(rt) True type(rs) == type(rl) False
Surely this isn't intentional?
Haikus are easy Most make very little sense Refrigerator -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20080826/2f616072/attachment.htm>
- Previous message: [Python-Dev] Confusing listreverseiterator Behavior
- Next message: [Python-Dev] Confusing listreverseiterator Behavior
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]