python中有顺序的字典

lovetysx 2009-12-09 10:14:16
请问python中有没有像java里面linkedHashMap一样的集合API ,可以记住数据存入的顺序?
...全文
116 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
notax 2009-12-10
  • 打赏
  • 举报
回复
查了一下python 3.1 是有类似的OrderedDict,看看是不是你要的? (dictionary with insertion order)

自己试了试python 3.1(的OrderedDict,大概是这样用的

>>> from collections import OrderedDict
>>>
>>> d = dict([('first', 1), ('second', 2), ('third', 3)])
>>> d.items()
dict_items([('second', 2), ('third', 3), ('first', 1)])
>>>
>>> od = OrderedDict([('first', 1), ('second', 2), ('third', 3)])
>>> od.items()
ItemsView(OrderedDict([('first', 1), ('second', 2), ('third', 3)]))
>>>
>>>
很少用 python 3.1


python2。5吗,有一个库
http://www.xs4all.nl/~anthon/Python/ordereddict/
lovetysx 2009-12-10
  • 打赏
  • 举报
回复
非常感谢2位的回答
angel_su 2009-12-09
  • 打赏
  • 举报
回复
看看http://www.python.org/dev/peps/pep-0372/

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧