简体   繁体   中英

How can i sort python dictionary by time in descending order

我必须对键为日期时间格式的字典进行排序,我必须按日期时间降序对字典进行排序。

There are few ways to sort dictionary in Python: You can use sorted method for list of keys:

for key in sorted(mydict):
     print "%s: %s" % (key, mydict[key])

Or you can use (I think that's a better way)

from collections import OrderedDict

Check out the usage here https://docs.python.org/2/library/collections.html#ordereddict-examples-and-recipes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM