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_Colors_Position_Variable Length Array - Fatal编程技术网

如何在python中查找列表项的位置?

如何在python中查找列表项的位置?,python,list,colors,position,variable-length-array,Python,List,Colors,Position,Variable Length Array,我有两张单子。第一个列表具有特定的长度,第二个列表具有不稳定的长度。我想分配两个列表中的项目。 我使用color\u index=sel\u pos%(len(colors))。sel_pos是项目在不稳定列表中的位置。 如何每次查找位置?使用l.index(n)在列表l中查找n的索引 >>> x = [1,3,7] >>> x.index(3) 1 您可以使用Index函数获取元素并在列表中返回该元素的索引: indexNumber = MyList.In

我有两张单子。第一个列表具有特定的长度,第二个列表具有不稳定的长度。我想分配两个列表中的项目。 我使用
color\u index=sel\u pos%(len(colors))
。sel_pos是项目在不稳定列表中的位置。 如何每次查找位置?

使用
l.index(n)
在列表
l
中查找
n
的索引

>>> x = [1,3,7]
>>> x.index(3)
1

您可以使用Index函数获取元素并在列表中返回该元素的索引:

indexNumber = MyList.Index(Element)

list.index()
?:或者我还不明白这个问题。。。请澄清问题一点也不清楚。能否提供代码示例,以便我们更容易理解您的问题?
index
区分大小写
indexNumber = MyList.Index(Element)