How do I randomize the numbers in a for loop in python 2.7.5? The for loop looks like this: for i in[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]: I already tried using the import random thing, maybe I wasn't using it right, but I don't know.
Asked
Active
Viewed 238 times
-1
-
Also, googling for "python list in random order" gives lots of links to answers immediately. https://www.google.com.au/#q=python+list+in+random+order – sashkello Jan 01 '14 at 23:53
1 Answers
3
import random
lst = [1,2,3,4,5,6,7,8,9,10]
random.shuffle(lst)
for e in lst:
# do your stuff

pkacprzak
- 5,537
- 1
- 17
- 37