mardi 6 décembre 2016

Python: How to random shuffle a list where each variable will end up in a new place

I would like to random shuffle a list so that each variable in the list when shuffled gets put in a new place in the list.

What I am currently doing:

list = ['a', 'b','c', 'd'];
random.shuffle(list)

list
['c','b','d','a']

With this method I shuffle the list but it is still possible to have a variable end up in the same place in this case 'b'.

My desired output

completely shuffled list

['c','a','d','b']

I appreciate any help. I am new to python but please let me know if any further information is needed.




Aucun commentaire:

Enregistrer un commentaire