
April 29, 2010
11:01 a.m.
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