mercredi 26 mai 2021

Randomize list without same entry successively

order_list_raw = []
for i in range(1, 73):
    order_list_raw.append(1)
    order_list_raw.append(2)
    order_list_raw.append(3)

How can I create the same list with a randomized order but without having the same entry successively (e.g. "1, 3, 2" is okay but not "1, 1, 3").

For randomization I would create a new list like this:

order_list = random.sample(order_list_raw, len(order_list_raw))



Aucun commentaire:

Enregistrer un commentaire