[Python-ideas] Reversable

cool-RR cool-rr at cool-rr.com
Thu Apr 29 03:15:22 CEST 2010


On Wed, Apr 28, 2010 at 1:00 PM, Paul Moore <p.f.moore at gmail.com> wrote:

> On 28 April 2010 11:48, cool-RR <cool-rr at cool-rr.com> wrote:
> > Does anyone else care to express their opinion about the Reversable
> > suggestion?
>
> I think you need some more convincing use cases, and a better
> explanation of how you'd see it working. As things stand, it sounds
> like you're just suggesting it for completeness' sake. I assume you're
> expecting an implementation which checks if the type is an instance of
> Sequence or has a callable attribute __reversed__?
>
> Then again, I'm not a great user of ABCs in any case - easier to ask
> forgiveness and all that, I'd tend to just use reversed() and be
> prepared to deal with an error if the caller passed something
> non-reversible (maybe just by expecting the caller to deal with the
> exception, because they didn't satisfy the input requirements).
>
> Paul.
>

I agree with your criticisms. I was indeed offering it for completeness'
sake, I think that when I needed it, I had some iterable that I didn't know
if I could use `reversed` on.

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.)

Ram.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20100429/e1603fb4/attachment.html>


More information about the Python-ideas mailing list