gpt4 book ai didi

python - 如果我的日期在字符串中,我如何在 Python 中对这个列表进行排序?

转载 作者:太空狗 更新时间:2023-10-29 17:21:05 25 4
gpt4 key购买 nike

[{'date': '2010-04-01', 'people': 1047, 'hits': 4522}, {'date': '2010-04-03', 'people': 617, 'hits': 2582}, {'date': '2010-04-02', 'people': 736, 'hits': 3277}]

假设我有这个列表。我如何按“日期”排序,这是字典中的一个项目。但是,“日期”是一个字符串...

最佳答案

.sort(key=lambda x: datetime.datetime.strptime(x['date'], '%Y-%m-%d'))

关于python - 如果我的日期在字符串中,我如何在 Python 中对这个列表进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2589479/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com