**Text generator, version 1: # Read text from a file, building a dictionary as we go # each key is a word in the text; the value is the list # of words that follow that word in the text. # Print random words, based on the dictionary. # Sample input text and the dictionary that is built for it: Happy day and Happy year and sad minute. {'': ['Happy'], 'and': ['Happy', 'sad'], 'minute.': [''], 'sad': ['minute.'], 'year': ['and'], 'day': ['and'], 'Happy': ['day', 'year']} **Text generator, version 2: # Read text from a file, building a dictionary as we go # Prefix is an integer. Suppose it is 2. Then, we will # keep track of the words that follow each pair of # words in the text. # # Each key is a tuple of words in the text; the value is the list # of words that follow those words in the text. # Print random words, based on the dictionary. # Sample input text and the dictionary that is built for it: Happy day and Happy day but Sad minute so Sad minute drats! with prefix set at 2: {('Happy', 'day'): ['and', 'but'], ('', 'Happy'): ['day'], ('minute', 'so'): ['Sad'], ('Sad', 'minute'): ['so', 'drats!'], ('day', 'and'): ['Happy'], ('minute', 'drats!'): [''], ('', ''): ['Happy'], ('but', 'Sad'): ['minute'], ('and', 'Happy'): ['day'], ('day', 'but'): ['Sad'], ('so', 'Sad'): ['minute']}