
On Thu, Apr 29, 2010 at 1:01 PM, Paul Moore <p.f.moore@gmail.com> wrote:
On 29 April 2010 02:15, cool-RR <cool-rr@cool-rr.com> wrote:
Though this leads me to another thought: Maybe we should have an argument to `reversed` which will instruct it to make a list out of the iterable and then return the `reversed` of that list, but only when the original iterable is not naturally reversible. This way you could be sure that `reversed` will work on any iterable. (When you don't care much about performance, of course.)
def reversed_anything(a): try: return reversed(a) except TypeError: return reversed(list(a))
Paul
Yes, I'm aware the implementation is simple. I was not asking for an implementation. I was just raising the idea that it should be part of the builtin `reversed`. But since there are no +1s, I guess not. Ram.