Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- """
- db is a defaultdict(list) like this: {(word1, word2): [possible words]}
- """
- CHAIN_LENGTH = 2
- STOP_WORD = '\x02'
- MAX_WORDS = 50
- def generate_message(db):
- key = random.choice(list(db.keys()))
- gen_words = []
- for i in range(MAX_WORDS):
- gen_words.append(key[0])
- next_word = random.choice(db[key])
- if not next_word or next_word is STOP_WORD:
- break
- key = key[1:] + (next_word,)
- return ' '.join(gen_words)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement