Where should I declare a list of 5,000+ words?

Posted by user647362 on Stack Overflow See other posts from Stack Overflow or by user647362
Published on 2012-06-24T21:07:07Z Indexed on 2012/06/24 21:15 UTC
Read the original article Hit count: 105

Filed under:

I am writing a game in python in which I must periodically pull a random word from a list of words. When I prototyped my game I declared a word_list = ['cat','dog','rat','house'] of ten words at the top of one of my modules. I then use choice(word_list) to get a random word. However, I must must change this temporary hack into something more elegant because I need to increase the size of the word list to 5,000+ words. If I do this in my current module it will look ridiculous.

Should I put all of these words in a flat txt file, and then read from that file as I need words? If so, how would I best do that? Put each word an a separate line and then read one random line? I'm not sure what the most efficient way is.

© Stack Overflow or respective owner

Related posts about python