Does anyone know a way to scramble the elements in a list?
>>> import random
>>> thelist = ['a', 'b', 'c', 'd']
>>> random.shuffle(thelist)
>>> thelist
['d', 'a', 'c', 'b']
Your result will (hopefully!) vary.
import random
random.shuffle(thelist)
Note, this shuffles the list in-place.
Use the random.shuffle()
function:
random.shuffle(thelist)