jeudi 28 janvier 2021

Random choosing 2 dictionaries: with same value

From a dictionary I wanna choose 2 dictionaries randomly who have their value[0] == 'C'.

d = {"1": ('B', [3, 4, 8]), "2": ('C', [2, 6, 8]), "3": ('C', [9, 10, 11, 13]), "4": ("E", [14, 15, 16, 17]), "5": ("C", [20])}
for key, val in d.items():
        if val[0] == 'B':

            b = val[0] == 'C'
            res = key, val = random.choice(list(d.items()))
            print(res)

e = {"2": ('C', [2, 6, 8]), "3": ('C', [9, 10, 11, 13])}
e = {"2, 3": ('C', [2, 6, 8] , [9, 10, 11, 13])}



Aucun commentaire:

Enregistrer un commentaire