[Python] random.choice from set?

Discussão em 'Python' iniciado por Stack, Fevereiro 6, 2025.

  1. Stack

    Stack Membro Participativo

    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 can I work around this?

    import random

    aiTurn = True
    while aiTurn == True:
    allLetters = set(list('abcdefghijklmnopqrstuvwxyz'))
    aiGuess = random.choice(allLetters)
    print(aiGuess)

    Continue reading...

Compartilhe esta Página