Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.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_Python 3.x_List_Sorting - Fatal编程技术网

Python 从索引中排序列表

Python 从索引中排序列表,python,python-3.x,list,sorting,Python,Python 3.x,List,Sorting,我有一个列表,其中有一些从文本文件输入的值。例如,假设列表是 a = ["Hello 2476 hey!", " hey 1534 hello!", " 2323"] 我想从第六个索引开始排序到第十个索引。我不知道该怎么做,即使搜索了这么多。感谢您的帮助 您可以在一个切片上使用sorted(),然后将结果分配回切片:a[6:]=sorted(a[6:]),它只是输出整个字符串。问题是如何按第7个索引对字符串进行排序?或者只对第7个索引之后的列表中的项目进行排序?排序(a,ke

我有一个列表,其中有一些从文本文件输入的值。例如,假设列表是

a = ["Hello 2476 hey!", "  hey 1534     hello!", "     2323"]

我想从第六个索引开始排序到第十个索引。我不知道该怎么做,即使搜索了这么多。感谢您的帮助

您可以在一个切片上使用sorted(),然后将结果分配回切片:a[6:]=sorted(a[6:]),它只是输出整个字符串。问题是如何按第7个索引对字符串进行排序?或者只对第7个索引之后的列表中的项目进行排序?
排序(a,key=lambda s:s[6])
?似乎您正在尝试使用切片和字典排序将已经可以做的事情整合在一起
a = ['hack', 'the' , 'jack', 'with' , 'a' , 'mac' , 'on' , 'the' , 'last', 'monday']

result = a[:6]+sorted(a[6:10])
print(result)