I would like to generate a random text using letter frequencies from a book in a .txt file, so that each new character (string.lowercase + ' ') depends on the previous one.
How do I use Markov chains to do so? Or is it simpler to use 27 arrays with conditional frequencies for each letter?
Consider using collections.Counter to build-up the frequencies when looping over the text file two letters at a time.
The two statements are equivalent. The Markov chain is what you’re doing. The 27 arrays with conditional frequencies is how you’re doing it.
Here is some dictionary based code to get you started: