jeudi 24 juin 2021

How to return the index of an element in a list of lists?

List = [[1,2,3],[4,5,6],[7,8,9]]

i want to pick a random element in List and return the index of it.

when I do:

List.index(random.choice(List[random.randint(0,2)]))

it obviously gives me an error, because the code only indexes the list-elements in List.

what I would like to have is something like:

output: The random number is: 4 and the index is: (1,0) or List[1][0]



Aucun commentaire:

Enregistrer un commentaire