Message196109
Reversed doesn't make sense for all iterables.
>>> a = set([1, 2, 3])
>>> a = iter(a) # No error
>>> a = reversed(a) # Not typically desirable
The point is that not all iterables are necessarily ordered. And a reversed function shouldn't operate on unordered types.
Here's the relevant section of the docs for reversed():
reversed(seq)
Return a reverse iterator. seq must be an object which has a
__reversed__() method or supports the sequence protocol (the
__len__() method and the __getitem__() method with integer
arguments starting at 0).
Your point about the sorted()'s behavior seems like a fair one, though. Perhaps it does make sense to support implicit conversion to lists for generator objects passed to reversed(). |
|
Date |
User |
Action |
Args |
2013-08-25 01:53:05 | madison.may | set | recipients:
+ madison.may, rhettinger, dstufft |
2013-08-25 01:53:05 | madison.may | set | messageid: <1377395585.27.0.432662007885.issue18826@psf.upfronthosting.co.za> |
2013-08-25 01:53:05 | madison.may | link | issue18826 messages |
2013-08-25 01:53:04 | madison.may | create | |
|