gpt4 book ai didi

python - 对 python 数组进行排序

转载 作者:太空宇宙 更新时间:2023-11-04 07:12:38 25 4
gpt4 key购买 nike

opt=[]
opt=["opt3","opt2","opt7","opt6","opt1"]
for i in range(len(opt)):
print opt[i]

上面的输出是

opt3,opt2,opt7,opt6,opt1

如何对上面的数组进行升序排序..

最佳答案

使用.sort()如果你想对原始列表进行排序。 (opt.sort())

使用sorted()如果你想要它的排序副本。

关于python - 对 python 数组进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3470436/

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