[Python-Dev] Add __reversed__ methods for dict

Ramsey D'silva ramseydsilva at gmail.com
Fri May 25 19:55:34 EDT 2018


I am also in agreement.

On Fri, May 25, 2018, 13:49 Guido van Rossum <guido at python.org> wrote:

> OK, +1
>
> On Fri, May 25, 2018 at 10:26 AM, Raymond Hettinger <
> raymond.hettinger at gmail.com> wrote:
>
>>
>>
>> > On May 25, 2018, at 9:32 AM, Antoine Pitrou <solipsis at pitrou.net>
>> wrote:
>> >
>> > It's worth nothing that OrderedDict already supports reversed().
>> > The argument could go both ways:
>> >
>> > 1. dict is similar to OrderedDict nowadays, so it should support
>> >   reversed() too;
>> >
>> > 2. you can use OrderedDict to signal explicitly that you care about
>> >   ordering; no need to add anything to dict.
>>
>> Those are both valid sentiments :-)
>>
>> My thought is that guaranteed insertion order for regular dicts is brand
>> new, so it will take a while for the notion settle in and become part of
>> everyday thinking about dicts.  Once that happens, it is probably
>> inevitable that use cases will emerge and that __reversed__ will get added
>> at some point.  The implementation seems straightforward and it isn't much
>> of a conceptual leap to expect that a finite ordered collection would be
>> reversible.
>>
>> Given that dicts now track insertion order, it seems reasonable to want
>> to know the most recent insertions (i.e. looping over the most recently
>> added tasks in a task dict).  Other possible use cases will likely
>> correspond to how we use the Unix tail command.
>>
>> If those use cases arise, it would be nice for __reversed__ to already be
>> supported so that people won't be tempted to implement an ugly workaround
>> using popitem() calls followed by reinsertions.
>>
>>
>> Raymond
>>
>> .
>>
>> _______________________________________________
>> Python-Dev mailing list
>> Python-Dev at python.org
>> https://mail.python.org/mailman/listinfo/python-dev
>> Unsubscribe:
>> https://mail.python.org/mailman/options/python-dev/guido%40python.org
>>
>
>
>
> --
> --Guido van Rossum (python.org/~guido)
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/ramseydsilva%40gmail.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20180525/0caefcf7/attachment.html>


More information about the Python-Dev mailing list