gpt4 book ai didi

Python列表降序排序

转载 作者:IT老高 更新时间:2023-10-28 12:07:37 26 4
gpt4 key购买 nike

如何按降序排列此列表?

timestamps = [
"2010-04-20 10:07:30",
"2010-04-20 10:07:38",
"2010-04-20 10:07:52",
"2010-04-20 10:08:22",
"2010-04-20 10:08:22",
"2010-04-20 10:09:46",
"2010-04-20 10:10:37",
"2010-04-20 10:10:58",
"2010-04-20 10:11:50",
"2010-04-20 10:12:13",
"2010-04-20 10:12:13",
"2010-04-20 10:25:38"
]

最佳答案

这将为您提供数组的排序版本。

sorted(timestamps, reverse=True)

如果你想就地排序:

timestamps.sort(reverse=True)

查看 Sorting HOW TO 上的文档

关于Python列表降序排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4183506/

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