I have a list of strings:
lst = ["orange", "yellow", "green"]
and I want to randomly repeat the values of strings for a given length.
This is my code:
import itertools
lst = ["orange", "yellow", "green"]
list(itertools.chain.from_iterable(itertools.repeat(x, 2) for x in lst))
This implementation repeats but not randomly and also it repeats equally, whereas it should be random as well with the given length.
Aucun commentaire:
Enregistrer un commentaire