Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python字典中对日期列表进行排序_Python_Sorting - Fatal编程技术网

在python字典中对日期列表进行排序

在python字典中对日期列表进行排序,python,sorting,Python,Sorting,我试图找出如何在python字典中对日期列表进行排序。例如,如果我在字典中有如下日期和名称: John 11/09/1998 Tom 02/01/1995 Steve 07/01/1988 Mike 12/12/2001 我希望对它们进行排序,以便最近的日期是第一个,最早的日期是最后一个,即 Mike 12/12/2001 # this will be first Steve 07/01/1988 # this will be last in my above example. 从我一直在阅

我试图找出如何在python字典中对日期列表进行排序。例如,如果我在字典中有如下日期和名称:

John 11/09/1998
Tom 02/01/1995
Steve 07/01/1988
Mike 12/12/2001
我希望对它们进行排序,以便最近的日期是第一个,最早的日期是最后一个,即

Mike 12/12/2001 # this will be first
Steve 07/01/1988 # this will be last in my above example.
从我一直在阅读的内容来看,使用下面的代码是解决这个问题的方法。你们有谁举个例子吗

sorted(dictionary.items(), key=operator.itemgetter(1), reverse=False)

您的日期是字符串格式还是datetime对象?我使用的是
datetime.strTime
,但如果您对这两种格式都有解决方案,我会感兴趣以供将来参考。02/01/1995应该是最后(最早)的日期,对吗?不,1988年的日期将是最后的日期。