You can use random.choice
and list.remove
from random import choice as rchoice
mylist = range(10)
while mylist:
choice = rchoice(mylist)
mylist.remove(choice)
print choice
Or, as @Henry Keiter
said, you can use random.shuffle
from random import shuffle
mylist = range(10)
shuffle(mylist)
while mylist:
print mylist.pop()
If you still need your shuffled list after that, you can do as follows:
...
shuffle(mylist)
mylist2 = mylist
while mylist2:
print mylist2.pop()
And now you will get an empty list mylist2, and your shuffled list mylist.
EDIT
About code you posted. You are writing random.choice(colors)
, but what random.choice
does? It choices random answer and returns(!) it. So you have to write
chosen_color = random.choice(colors)
if chosen_color == "red":
print "The color is red!"
colors.remove("red") ##Remove string from the list
chosen_number = random.choice(numbers)
if chosen_number == "2":
chosen_design = random.choice(design)