dimanche 21 octobre 2018

How to randomly replace a specific element in a list?

I have a list of lists. How do I create a function which randomly replaces all instances of 10 with another number?

lst = [ [10, 100, 10 ], [10, 1000, 10], [100, 100000, 100], [10, 10, 0] ]

def random_replace10(num, lst):
   pass

print(random_replace10(2, lst))


>>> [ [10, 100, 2 ], [10, 1000, 10], [100, 100000, 100], [10, 10, 0] ]




Aucun commentaire:

Enregistrer un commentaire