2

I have two lists. The first list has a specific length and the second list has unstable length. I want to assign the items from two lists. I use colour_index = sel_pos%(len(colours)). The sel_pos is the item's position from the unstable list. How to find the position every time?

3 Answers3

9

Use l.index(n) to find index of n in list l.

>>> x = [1,3,7]
>>> x.index(3)
1
Moinuddin Quadri
  • 46,825
  • 13
  • 96
  • 126
0
colour_index = selections.index(txt)%(len(colours))
-1

You can use Index function which is get the element and return the index of it in the list:

indexNumber = MyList.Index(Element)
Reza Tanzifi
  • 572
  • 4
  • 13