A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2018-July/154774.html below:

[Python-Dev] [issue34221] Any plans to combine collections.OrderedDict with dict

[Python-Dev] [issue34221] Any plans to combine collections.OrderedDict with dictRaymond Hettinger raymond.hettinger at gmail.com
Fri Jul 27 02:35:42 EDT 2018
> On Jul 26, 2018, at 10:23 AM, Terry Reedy <tjreedy at udel.edu> wrote:
> 
> On python-idea,  Miro HronĨok asked today whether we can change the OrderedDict repr from, for instance,
> 
> OrderedDict([('a', '1'), ('b', '2')]) # to
> OrderedDict({'a': '1', 'b': '2'})
> 
> I am not sure what our repr change policy is, as there is a back-compatibility issue but I remember there being changes.

We are allowed to change the repr in future versions of the language.  Doing so does come at a cost though. There is a small performance penalty (see the timings below).  Some doctests will break.  And Python 3.8 printed output in books and blog posts would get shuffled if typed in to Python 3.5 -- this is problematic because one of the few remaining use cases for OrderedDict is to write code that is compatible with older Pythons.  

The proposed repr does look pretty but probably isn't worth the disruption.


Raymond

------------------

$ python3.7 -m timeit -r 7 'from collections import OrderedDict' "OrderedDict([('a', '1'), ('b', '2')])"
200000 loops, best of 7: 1.12 usec per loop
$ python3.7 -m timeit -r 7 'from collections import OrderedDict' "OrderedDict({'a': '1', 'b': '2'})"
200000 loops, best of 7: 1.22 usec per loop
$ python3.7 -m timeit -r 7 'from collections import OrderedDict' "OrderedDict([('a', '1'), ('b', '2')])"
200000 loops, best of 7: 1.13 usec per loop
$ python3.7 -m timeit -r 7 'from collections import OrderedDict' "OrderedDict({'a': '1', 'b': '2'})"
200000 loops, best of 7: 1.2 usec per loop
$ python3.7 -m timeit -r 7 'from collections import OrderedDict' "OrderedDict([('a', '1'), ('b', '2')])"
200000 loops, best of 7: 1.12 usec per loop
$ python3.7 -m timeit -r 7 'from collections import OrderedDict' "OrderedDict({'a': '1', 'b': '2'})"
200000 loops, best of 7: 1.2 usec per loop
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4