sorting a list of dictionary values by date in python

后端 未结 5 1277
遥遥无期
遥遥无期 2020-12-24 13:29

I have a list and I am appending a dictionary to it as I loop through my data...and I would like to sort by one of the dictionary keys.

ex:

data = \         


        
5条回答
  •  时光取名叫无心
    2020-12-24 14:11

    I actually had this almost exact question yesterday and solved it using search. The best answer applied to your question is this:

    from operator import itemgetter
    list.sort(key=itemgetter('date'), reverse=True)
    

提交回复
热议问题