Python list sort in descending order

前端 未结 6 831
小鲜肉
小鲜肉 2020-11-22 13:23

How can I sort this list in descending order?

timestamp = [
    \"2010-04-20 10:07:30\",
    \"2010-04-20 10:07:38\",
    \"2010-04-20 10:07:52\",
    \"2010         


        
6条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 13:47

    Since your list is already in ascending order, we can simply reverse the list.

    >>> timestamp.reverse()
    >>> timestamp
    ['2010-04-20 10:25:38', 
    '2010-04-20 10:12:13', 
    '2010-04-20 10:12:13', 
    '2010-04-20 10:11:50', 
    '2010-04-20 10:10:58', 
    '2010-04-20 10:10:37', 
    '2010-04-20 10:09:46', 
    '2010-04-20 10:08:22',
    '2010-04-20 10:08:22', 
    '2010-04-20 10:07:52', 
    '2010-04-20 10:07:38', 
    '2010-04-20 10:07:30']
    

提交回复
热议问题