【发布时间】:2012-08-31 13:33:07
【问题描述】:
for y in item:
print '%s %s %s' % (item[y]['light'], item[y]['time'], item[y]['name'])
产量:
10.38002 2.95000 earth
10.38000 12.04000 earth
10.28865 0.09789 earth
9.90000 12.50000 earth
9.77063 3.51299 earth
9.77000 13.40000 earth
10.38000000 1.26523000 moon
10.36000000 65.80305000 moon
10.31000000 1.72639000 moon
10.30000000 2.00000000 moon
10.33726 0.09833000 jupiter
10.30938 0.16622000 jupiter
10.24001 0.34554000 jupiter
10.24000 11.82214802 jupiter
10.23389 0.10840000 jupiter
10.20629 0.17732000 jupiter
我想根据第一个键对项目进行排序:'light'。
非常感谢任何帮助。
【问题讨论】:
-
你的意思是你想按值(键'light')排序。您是否搜索过 StackOverflow 以对字典进行排序?已经有很多好的答案了。
-
我尝试了很多答案。我现在正在尝试转换为列表,然后执行 thikonom 的 [建设性!] 答案。
标签: python sorting dictionary