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?
Asked
Active
Viewed 1.3k times
2
-
`list.index()` ? : http://stackoverflow.com/questions/176918/finding-the-index-of-an-item-given-a-list-containing-it-in-python Or I haven't understood the question... Please clarify – Julien Aug 26 '16 at 08:12
-
the question is not at all clear. – famagusta Aug 26 '16 at 08:13
-
Can you provide a code sample, so we can more easily understand your issue? – Poorkenny Aug 26 '16 at 09:28
3 Answers
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