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

前端 未结 5 974
一整个雨季
一整个雨季 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:19

    records = [
         {'date': '2010-04-01', 'people': 1047, 'hits': 4522}, 
         {'date': '2010-04-03', 'people': 617, 'hits': 2582}, 
         {'date': '2010-04-02', 'people': 736, 'hits': 3277}
         ]
    records.sort(key=lambda x: x['date'].split('-'))
    

提交回复
热议问题