Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Collections (2016, retired 2019) Sets Out Of This Word Game

James Estrada
seal-mask
.a{fill-rule:evenodd;}techdegree
James Estrada
Full Stack JavaScript Techdegree Student 25,866 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

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