0

I am in the early stages of learning at the moment and I'm attempting to make a simple little memory game.

The problem I am having is printing a different random item constantly until the list has been exhausted, whilst giving the user a little time between each output to remember it.

import random

List1 = ['item' , 'item' , 'ect']

Print(random.choice(List1))

input('press enter for next item')
MrWonderful
  • 2,530
  • 1
  • 16
  • 22

1 Answers1

2

Your simplest solution is probably to shuffle the list, then iterate over the shuffled list.

my_list = ['item' , 'item' , 'ect']
random.shuffle(my_list)   # my_list is now in random order

for item in my_list:
    print(item)

If for some reason you want to preserve the original order as well, make a copy of the list before shuffling it. (my_copy = my_list.copy())

Mark Reed
  • 91,912
  • 16
  • 138
  • 175
Ken Kinder
  • 12,654
  • 6
  • 50
  • 70
  • Also note the variable name choice `my_list`. You should in general not give variables capitalized names (there are certain special uses for those), or names like `list` that mean something to Python itself. – Mark Reed Jun 04 '20 at 14:46
  • Much appreciated! Thank you. – guessHue Jun 04 '20 at 14:56