<div dir="ltr"><div class="gmail_quote">On Mon, Apr 26, 2010 at 11:34 PM, George Sakkis <span dir="ltr"><<a href="mailto:george.sakkis@gmail.com">george.sakkis@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">On Mon, Apr 26, 2010 at 11:18 PM, cool-RR <<a href="mailto:cool-rr@cool-rr.com">cool-rr@cool-rr.com</a>> wrote:<br>
> On Mon, Apr 26, 2010 at 11:13 PM, Xavier Ho <<a href="mailto:contact@xavierho.com">contact@xavierho.com</a>> wrote:<br>
>><br>
>> On Tue, Apr 27, 2010 at 7:10 AM, cool-RR <<a href="mailto:cool-rr@cool-rr.com">cool-rr@cool-rr.com</a>> wrote:<br>
>>><br>
>>> Just something small that I thought of, and I haven't thought about this<br>
>>> deeply at all, so maybe this is way wrong. But: What about adding a<br>
>>> `Reversable` next to all the `Iterable` and `Container` and stuff?<br>
>><br>
>> You mean there is something Iterable we can't reverse by doing [::-1] or<br>
>> calling reversed() ? This idea feels a bit too general to be useful. Any<br>
>> rationales?<br>
>><br>
>> Cheers,<br>
>> Xav<br>
><br>
> As far as I know, iterables are generally not reversable. Try defining a<br>
> simple iterator, like a class with just an `__iter__` function, and run<br>
> `reversed` on it. You get `TypeError: argument to reversed() must be a<br>
> sequence`. (Which by the way is a bad error message.)<br>
> Am I missing something?<br>
<br>
</div></div>So what should reversed() (or a new Reversable()) return for, say,<br>
itertools.count() ?<br>
<br>
By the way, comp.lang.python [1] or the tutor mailing list [2] are<br>
more appropriate than python-ideas for asking<br>
questions "you haven't thought about deeply at all".<br>
<br>
George<br>
<br>
[1] <a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
[2] <a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
</blockquote></div><br>I'm not really understanding you, George. Am I getting something very wrong here? When you put `itertools.count()` into `reversed()`, you get an error, like you should, because it's not a sequence and it doesn't define `__reversed__`. So it's not a reversable object. I'm proposing to have a `Reversable` similar to `Iterable`, which checks the existence of `__reversed__` instead of `__iter__`.<div>
<br></div><div>Ram.</div></div>