random.choice from set? python
I'm working on an AI portion of a guessing game. I want the AI to select a random letter from this list. I'm doing it as a set so I can easily remove letters from the list as they are guessed in the game and are therefore no longer available to be guessed again.
it says "set" object isn't indexable. How do I work around this?
import random aiTurn=True while aiTurn == True: allLetters = set(list('abcdefghijklmnopqrstuvwxyz')) aiGuess=random.choice(allLetters) print (aiGuess)
>>> random.sample(set('abcdefghijklmnopqrstuvwxyz'), 1) ['f']
★ Back to homepage or read more recommendations: