import random import sys maxgen = 10000 nonword = '\n' w1 = w2 = nonword statetab = {} text = sys.stdin.read() words = text.split() for word in words: statetab.setdefault((w1, w2),[]).append(word) w1, w2 = w2, word # add tail statetab.setdefault((w1, w2),[]).append(nonword) # show mar words w1 = w2 = nonword for i in xrange(maxgen): suf = statetab[(w1,w2)] t = random.choice(suf) if t == nonword: break print t w1, w2 = w2, t
用户登录
还没有账号?立即注册
用户注册
投稿取消
文章分类: |
|
还能输入300字
上传中....