How do I sort this list in Python, if my date is in a String?

前端 未结 5 980
一整个雨季
一整个雨季 2020-11-29 08:38
[{\'date\': \'2010-04-01\', \'people\': 1047, \'hits\': 4522}, {\'date\': \'2010-04-03\', \'people\': 617, \'hits\': 2582}, {\'date\': \'2010-04-02\', \'people\': 73         


        
5条回答
  •  臣服心动
    2020-11-29 09:23

    Fortunately, ISO format dates, which seems to be what you have here, sort perfectly well as strings! So you need nothing fancy:

    import operator
    yourlistofdicts.sort(key=operator.itemgetter('date'))
    

提交回复
热议问题