[New-bugs-announce] [issue18826] reversed() requires a sequence - Could work on any iterator?

Donald Stufft report at bugs.python.org
Sat Aug 24 21:08:22 CEST 2013


New submission from Donald Stufft:

I noticed today that the builtin reversed() requires an explicit sequence and won't work with an iterator instead it throws a TypeError like:

>>> reversed(x for x in [1, 2, 3])
TypeError: argument to reversed() must be a sequence

It would be really great if reversed() worked on iterators too. Currently it requires an explicit list() before you can sent it back into reversed() which seems like it hurts readability.

For what it's worth I discovered this when trying to reverse the output of itertools.dropwhile.

----------
messages: 196090
nosy: dstufft
priority: normal
severity: normal
status: open
title: reversed() requires a sequence - Could work on any iterator?

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18826>
_______________________________________


More information about the New-bugs-announce mailing list