[Python-ideas] Reversable

cool-RR cool-rr at cool-rr.com
Mon Apr 26 23:18:26 CEST 2010

On Mon, Apr 26, 2010 at 11:13 PM, Xavier Ho <contact at xavierho.com> wrote:

> On Tue, Apr 27, 2010 at 7:10 AM, cool-RR <cool-rr at cool-rr.com> wrote:
>> Just something small that I thought of, and I haven't thought about this
>> deeply at all, so maybe this is way wrong. But: What about adding a
>> `Reversable` next to all the `Iterable` and `Container` and stuff?
> You mean there is something Iterable we can't reverse by doing [::-1] or
> calling reversed() ? This idea feels a bit too general to be useful. Any
> rationales?
> Cheers,
> Xav

As far as I know, iterables are generally not reversable. Try defining a
simple iterator, like a class with just an `__iter__` function, and run
`reversed` on it. You get `TypeError: argument to reversed() must be a
sequence`. (Which by the way is a bad error message.)

Am I missing something?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20100426/958ff8a2/attachment.html>

More information about the Python-ideas mailing list