> On May 25, 2018, at 9:32 AM, Antoine Pitrou <solip...@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@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to