thelist = ['a','b','c','d']
How can I scramble them in Python?
>>> import random >>> thelist = ['a', 'b', 'c', 'd'] >>> random.shuffle(thelist) >>> thelist ['d', 'a', 'c', 'b']
Your result will (hopefully!) Change.
import random random.shuffle(thelist)
Note that this shuffles the list in place.
Use function random.shuffle():
random.shuffle()
random.shuffle(thelist)
Use the shufflefunction from the module random:
shuffle
random
>>> from random import shuffle >>> thelist = ['a','b','c','d'] >>> shuffle(thelist) >>> thelist ['c', 'a', 'b', 'd']