Python Python Collections Sets Out Of This Word Game

James Estrada
James Estrada
17,569 Points

Why Can't We use a Set for our Constant 'WORDS'?

if I change the constant 'WORDS' from a tuple to a set, I get the following error:

TypeError: 'set' object does not support indexing

Is this error produced when we use the random function?

challenge_word = random.choice(WORDS)

I thought a set and a tuple were pretty much the same thing, and that you could find an element inside of them.

1 Answer

Ralph Khreish
Ralph Khreish
4,586 Points

It's because we don't want to modify it, its a constant. if we used a set, we could remove words and modify them in the set. Using a tuple makes it so we can't modify the word