Implementing Hangman. I want to randomly select the length of the word, taking into account how many words of a given length are in the wordlist - ie. 12-letter words should be chosen less frequently than 5-letter ones, because there are fewer of the former.
It doesn't look like the random module will do that easily.
I could hack something semi-ugly together, but am looking for suggestions of a tidy way to do it.
UPDATE to remove some confusion:
This is a cheating version of hangman: it specifies a word-length at the beginning, but doesn't actually pick the word until it absolutely has to.
Here's the full problem description (from Chapter 8 of the book Think Like a Programmer):
Write a program that will be Player 1 in a text-based version of hangman (that is, you don't actually have to draw a hanged man—just keep track of the number of incorrect guesses). Player 2 will set the difficulty of the game by specifying the length of the word to guess as well as the number of incorrect guesses that will lose the game. The twist is that the program will cheat. Rather than actually picking a word at the beginning of the game, the program may avoid picking a word, so long as when Player 2 loses, the program can display a word that matches all the information given to Player 2. The correctly guessed letters must appear in their correct positions, and none of the incorrectly guessed letters can appear in the word at all. When the game ends, Player 1 (the program) will tell Player 2 the word that was chosen. Therefore, Player 2 can never prove that the game is cheating; it's just that the likelihood of Player 2 winning is small.