[Python-Dev] Add reversed methods for dict (original) (raw)
Guido van Rossum guido at python.org
Fri May 25 13:48:09 EDT 2018
- Previous message (by thread): [Python-Dev] Add __reversed__ methods for dict
- Next message (by thread): [Python-Dev] Add __reversed__ methods for dict
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20180525/201eb327/attachment-0001.html>
- Previous message (by thread): [Python-Dev] Add __reversed__ methods for dict
- Next message (by thread): [Python-Dev] Add __reversed__ methods for dict
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]