Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用整数和无分隔符对字符串列表进行排序_Python_List_Sorting - Fatal编程技术网

Python 如何使用整数和无分隔符对字符串列表进行排序

Python 如何使用整数和无分隔符对字符串列表进行排序,python,list,sorting,Python,List,Sorting,我正试着对这个列表进行排序。我的文件如下所示:“crown”+“t”+“0.01” 我想用t随t的增加对这个列表进行排序。 谢谢你 import glob txtfiles = [] for file in glob.glob("crown*0.01"): txtfiles.append(file) print(txtfiles) 输出: ['crown0.90.01', 'crown0.250.01', 'crown0.550.01', 'crown0.650.

我正试着对这个列表进行排序。我的文件如下所示:“crown”+“t”+“0.01” 我想用t随t的增加对这个列表进行排序。 谢谢你

import glob

txtfiles = []
for file in glob.glob("crown*0.01"):
    txtfiles.append(file)
print(txtfiles)
输出:

['crown0.90.01', 'crown0.250.01', 'crown0.550.01', 'crown0.650.01', 'crown1.90.01', 'crown2.10.01', 'crown0.850.01', 'crown0.20.01', 'crown0.80.01', 'crown0.10.01']
sort()
函数将起作用。您可以尝试以下方法:-

l = ['crown0.90.01', 'crown0.250.01', 'crown0.550.01', 'crown0.650.01', 'crown1.90.01', 'crown2.10.01', 'crown0.850.01', 'crown0.20.01', 'crown0.80.01', 'crown0.10.01']
l.sort()
print(l)
输出:-

['crown0.10.01', 'crown0.20.01', 'crown0.250.01', 'crown0.550.01', 'crown0.650.01', 'crown0.80.01', 'crown0.850.01', 'crown0.90.01', 'crown1.90.01', 'crown2.10.01']

非常感谢。我不认为这个函数能够做到这一点。。。