Jos*_*son 6 python dictionary ordereddictionary
我已经看过(并写过)了很多这方面的实现.有没有被认为是最好的或正在成为标准?
我所说的有序dict是指对象有一些键的顺序概念,类似于PHP中的数组.
来自PEP 372的冒险似乎是一个强有力的候选人,但它并不完全清楚它是胜利者.
sah*_*sah 12
Raymond Hettinger的这个版本是将在Python 2.7中出现的collections.OrderedDict的替代品:http://pypi.python.org/pypi/ordereddict
集合文档的dev版本说它相当于Python 2.7中的内容,所以它很可能是顺利过渡到Python附带的版本.
我把它放在PyPI中,所以你可以安装它easy_install ordereddict
,并像这样使用它:
from ordereddict import OrderedDict
d = OrderedDict([("one", 1), ("two", 2)])
Run Code Online (Sandbox Code Playgroud)