j: Next unread message
k: Previous unread message
j a: Jump to all threads
j l: Jump to MailingList overview
On Fri, May 25, 2018 at 10:26 AM, Raymond Hettinger email@example.com wrote:
On May 25, 2018, at 9:32 AM, Antoine Pitrou firstname.lastname@example.org wrote:
It's worth nothing that OrderedDict already supports reversed(). The argument could go both ways:
dict is similar to OrderedDict nowadays, so it should support reversed() too;
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.
Python-Dev mailing list Python-Dev@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)