-4
sorted_event_types={}
for key,value in sorted(event_types.items()):
sorted_event_types[key]=value
(Pdb) print sorted_event_types
{'ch': 1, 'eh': 2, 'oh': 3, 'ah': 0, 'as': 1, 'cs': 0, 'os': 5, 'es': 9}
(Pdb) event_types
{'as': 1, 'ch': 1, 'eh': 2, 'oh': 3, 'cs': 0, 'ah': 0, 'os': 5, 'es': 9}
我想排序字典,并保持它的方式。排序字典
输出应该{'ah': 1, 'as': 1, 'ch': 2, 'cs': 3, 'eh': 0, ...}
那么究竟是什么问题? – Mureinik
查看[OrderedDict](https://docs.python.org/3/library/collections.html#collections.OrderedDict)(尽管我可能会将它变成一个列表,而不是我喜欢的分隔) – user2864740
可悲的是,重复问题OrderedDict(是否合适)答案相当埋藏.. – user2864740