Get Index of List in a List by What is Inside

listOfLists = [[], [], [], ['jeff'], []]

So I have many lists within a list. How would I get the index of the list containing the name jeff?

Thanks.

def GetIndex(listOfLists, name):
…for num, subList in enumerate(listOfLists):
…if name in subList:
…return num
…# If nothing found…
…return -1


for subList in listOfLists:
    for item in subList:
        if item == "jeff":
            return listOfLists.index(subList)

That should probably work.

lol:


listOfLists.index(['jeff'])

Honestly, this data structure does not look like it fits your needs. Searching such a structure is inefficient, hard to maintain and hard to understand.

But I do not know you further requirements.

That works, thanks guys!