Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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_Numbers - Fatal编程技术网

Python 混合数值列表的排序列表

Python 混合数值列表的排序列表,python,list,sorting,numbers,Python,List,Sorting,Numbers,场景:包含具有各种值的列表记录的“行”的列表 问题:List.sort没有考虑数值,因此值会到处都是 i、 E9在80之后出现在列表中 我试过使用 list.sort(key=operator.itemgetter[index]) 做一个 list.sort(lambda x,y:int(x[index])<int(y[index])) list.sort(lambda x,y:int(x[index])使用转换后的数字作为键 L.sort(key=lambda x: int(x[i

场景:包含具有各种值的列表记录的“行”的列表

问题:List.sort没有考虑数值,因此值会到处都是

i、 E9在80之后出现在列表中

我试过使用

list.sort(key=operator.itemgetter[index])
做一个

list.sort(lambda x,y:int(x[index])<int(y[index])) 

list.sort(lambda x,y:int(x[index])使用转换后的数字作为键

L.sort(key=lambda x: int(x[index]))

使用转换后的数字作为键

L.sort(key=lambda x: int(x[index]))

这是正确的,但是operator.itemgetter是一个函数,因此语法是:

list.sort(key=operator.itemgetter(index))
或者,使用lambda:

list.sort(key=lambda x: x[index])
关键参数是要走的路,cmp参数已在Python 3中删除。如果仍要使用它,则应使用cmp()内置函数来实现比较器:

list.sort(cmp=lambda x, y: cmp(x[index], y[index]))

另请参见:

您的思路是正确的,但是operator.itemgetter是一个函数,因此语法是:

list.sort(key=operator.itemgetter(index))
或者,使用lambda:

list.sort(key=lambda x: x[index])
关键参数是要走的路,cmp参数已在Python 3中删除。如果仍要使用它,则应使用cmp()内置函数来实现比较器:

list.sort(cmp=lambda x, y: cmp(x[index], y[index]))

另请参见:

列表中的值是什么-我们需要更多信息列表中的值是什么-我们需要更多信息