[Python-ideas] Reversable
cool-RR
cool-rr at cool-rr.com
Thu Apr 29 13:22:41 CEST 2010
On Thu, Apr 29, 2010 at 1:01 PM, Paul Moore <p.f.moore at gmail.com> wrote:
> On 29 April 2010 02:15, cool-RR <cool-rr at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20100429/3bc8f697/attachment.html>
More information about the Python-ideas
mailing list