thelist = ['a','b','c','d'] How I can to scramble them in Python?
5 Réponses :
Utilisez la fonction shuffle code> du module code> aléatoire code>:
Hé, comment tu as une sortie différente à Peter? ;)
Qui d'autre est allé directement au bouton "Ajouter un commentaire" à Lambast, avant de voir le clin d'œil? : P
import random random.shuffle(thelist) Note, this shuffles the list in-place.
>>> import random >>> thelist = ['a', 'b', 'c', 'd'] >>> random.shuffle(thelist) >>> thelist ['d', 'a', 'c', 'b'] Your result will (hopefully!) vary.
en place fort> shuffle (modifie V, renvoie non) pas sur place strong> shuffle (si vous ne le faites pas Voulez-vous modifier le tableau d'origine, crée une copie mélangée) p>
Je pense que la réponse pourrait être
aléatoire.shuffle code>. 8-)Duplicaté exact: Stackoverflow.com/Questions/473973/shauffe- An-Array-with-pyt hon