[Python-ideas] Reversable

George Sakkis george.sakkis at gmail.com
Mon Apr 26 23:34:11 CEST 2010


On Mon, Apr 26, 2010 at 11:18 PM, cool-RR <cool-rr at cool-rr.com> wrote:
> 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?

So what should reversed() (or a new Reversable()) return for, say,
itertools.count() ?

By the way, comp.lang.python [1] or the tutor mailing list [2] are
more appropriate than python-ideas for asking
questions "you haven't thought about deeply at all".

George

[1] http://mail.python.org/mailman/listinfo/python-list
[2] http://mail.python.org/mailman/listinfo/tutor



More information about the Python-ideas mailing list