一种更整洁的文字顺序数据编码方法
odictliteral的Python项目详细描述
提供了一种从python源代码指定有序字典的好方法。
示例:
>>> from odictliteral import odict >>> x = odict[1:2,3:4] >>> print(x) odict[1: 2, 3: 4]
您可以使用odict替代ordereddict,否则,例如:
>>> y = odict( [(1,2), (3,4)] ) >>> print(y) odict[1: 2, 3: 4] >>> x == y True
您还应该能够将odict与ordereddicts结合使用:
>>> z = OrderedDict( [(1,2), (3,4)] ) >>> print(z) OrderedDict([(1, 2), (3, 4)]) >>> y == z True
差不多就这些了。应该与python兼容 2.7和python 3;需要“ordereddict”模块与python一起工作 2.4、2.5或2.6。