Skip to content

Instantly share code, notes, and snippets.

@benrules2
Created January 5, 2017 23:14
Show Gist options
  • Select an option

  • Save benrules2/8e5229cb1b9e8015744e599023943462 to your computer and use it in GitHub Desktop.

Select an option

Save benrules2/8e5229cb1b9e8015744e599023943462 to your computer and use it in GitHub Desktop.
Generate Markov Chain
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