I am trying to run this code from the beginners' python book Think Python to do Markov Analysis on a text file. When I run the code provided as a solution, I get an IndexError: List index out of range from the random.py module. What do I need to change?
The code should be the answer to Exercise 8 off of Think Python, but I can't get it to work.
Traceback:
Traceback (most recent call last):
File "test.py", line 115, in <module>
main(*sys.argv)
File "test.py", line 111, in main
random_text(n)
File "test.py", line 76, in random_text
start = random.choice(suffix_map.keys())
File "/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/random.py", line 274, in choice
return seq[int(self.random() * len(seq))] # raises IndexError if seq is empty
Edit: I am running it on a .txt file. It's the text of a book downloaded from Project Gutenburg.