Using Python's list index() method on a list of tuples or objects?

前端 未结 12 1482
说谎
说谎 2020-12-12 12:15

Python\'s list type has an index() method that takes one parameter and returns the index of the first item in the list matching the parameter. For instance:



        
12条回答
  •  离开以前
    2020-12-12 12:44

    ok, it might be a mistake in vals(j), the correction is:

    def getIndex(li,indices,vals):
    for pos,k in enumerate(lista):
        match = True
        for i in indices:
            if k[i] != vals[indices.index(i)]:
                match = False
                break
        if(match):
            return pos
    

提交回复
热议问题