This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: listreverseiterator has a decreasing len()
Type: behavior Stage:
Components: Versions: Python 3.0, Python 2.6
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: aronacher, georg.brandl, laxrulz777, rhettinger
Priority: low Keywords:

Created on 2008-08-26 20:17 by laxrulz777, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg71993 - (view) Author: Jeff Hall (laxrulz777) Date: 2008-08-26 20:17
reversed() built in is not functioning correctly with list (specifically
with len() )

l = [1,2,3,4]
rl = reversed(l)

<type 'listreverseiterator'>

vs. strings and tuples which just return 'reverse' objects

listreverseiterators apparently have a len() defined that changes with
each .next() call
msg71994 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-08-26 20:27
"reversed() built in is not functioning correctly with list" is wrong --
there is no problem with reversed() on lists.

The issue here is that the listreverseiterator has a strange __len__.
Note that other (reverse) iterators have no __len__ at all, so apart
from consistency there is nothing that "does not function correctly."
msg71995 - (view) Author: Armin Ronacher (aronacher) * (Python committer) Date: 2008-08-26 20:42
Just for the record.  This original discussion for this bug is here:
msg76787 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2008-12-02 21:34
Fixed r67478.
Date User Action Args
2022-04-11 14:56:38adminsetgithub: 47939
2008-12-02 21:34:18rhettingersetstatus: open -> closed
resolution: fixed
messages: + msg76787
2008-08-26 20:42:56aronachersetnosy: + aronacher
messages: + msg71995
2008-08-26 20:31:48georg.brandlsetassignee: rhettinger
title: reversed() not working as intended on lists -> listreverseiterator has a decreasing len()
nosy: + rhettinger
versions: + Python 2.6, Python 3.0, - Python 2.5
2008-08-26 20:27:24georg.brandlsetpriority: low
nosy: + georg.brandl
messages: + msg71994
2008-08-26 20:17:14laxrulz777create