Search code examples
pythonlistcolorspositionvariable-length-array

How to find the position of an item of a list in python?


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?


Solution

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

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