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}

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to