Created
January 5, 2017 23:14
-
-
Save benrules2/8e5229cb1b9e8015744e599023943462 to your computer and use it in GitHub Desktop.
Generate Markov Chain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def build_chain(text, chain = {}): | |
| words = text.split(' ') | |
| index = 1 | |
| for word in words[index:]: | |
| key = words[index - 1] | |
| if key in chain: | |
| chain[key].append(word) | |
| else: | |
| chain[key] = [word] | |
| index += 1 | |
| return chain |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment