[Python-ideas] Change repr of collections.OrderedDict to be more dict-like

Serhiy Storchaka storchaka at gmail.com
Fri Jul 27 07:24:29 EDT 2018


27.07.18 12:53, Chris Angelico пише:
>>>> from collections import OrderedDict
>>>> od = OrderedDict([('a', 1), ('b', 2)])
>>>> dict.__repr__(od)
> "{'a': 1, 'b': 2}"

dict.__repr__() can output items in wrong order.

 >>> from collections import OrderedDict
 >>> od = OrderedDict([('a', 1), ('b', 2)])
 >>> od.move_to_end('a')
 >>> print(repr(od))
OrderedDict([('b', 2), ('a', 1)])
 >>> print(dict.__repr__(od))
{'a': 1, 'b': 2}



More information about the Python-ideas mailing list