User:Amy Suo Wu/markov chains
< User:Amy Suo Wu
Revision as of 10:01, 24 May 2011 by Amy Suo Wu (talk | contribs)
the dog hacked my homework
#!/usr/bin/env.python
import random
#random library
# this is building the dictionary with {}
nextwords = {'he': ['saw'], 'saw': ['the'], 'the': ['cat','potato'], 'cat': ['before'], 'before': ['he'], 'potato': ['.']}
# assigning the item variable from the dictionary. e.g 'he'
focus = 'he'
# call the next words for what ever is stored in the variable focus variable
print nextwords[focus]
#next step is to get him to pick a random word from the values list in the dictionary. build a loop, start anywhere and assign it to variable (focus),
then search value accordingly and pick out a random word from the value. Then assign the value that he finds to the variable [focus]. jumping to the
next and then calling it focus. *still missing: storing what is finds in a list*
#dict(one=1, two=2)
#dict({'one': 1, 'two': 2})
#dict(zip(('one', 'two'), (1, 2)))
#dict([['two', 2], ['one', 1]])