mercredi 7 décembre 2016

Retrieve random object in a list which contains multiple lists.

I'm having trouble of finding a way to randomly retrieve a specific object from a list which contains multiple lists. I have tried from random import choice but I didn't manage to get "b" for example, instead I got the whole list with index 0.

Second question, how do I count how many "b" there are in the list l? When I use l.count it always says 0 since it counts how many "b"s there are in the list l and not the lists in the list l, as I understood it.

For example:

l = [["f","g","h","j"],["a","b","c","d"]]




Aucun commentaire:

Enregistrer un commentaire