<jupyter_start><jupyter_text>Mimicking dict exerciseCopyright 2010 Google Inc. Licensed under the Apache License, Version 2.0 Google's Python Class:  IntroductionIn this exercise, you will create a mimicking dictionary.This dictionary will encode word-pair frequencies, which we will use toemit random text that matches the structure of the source file.First, we will read in the file specified on the command line,and do a simple `split()` on whitespace to obtain all the words in the file.Rather than read the file line by line, it's easier to readit into one giant string and split it once.You will write a function to build a "mimic" dict that maps each word thatappears in the file to a list of all the words that immediately followthat word in the file.The list of words can be be in any order and should include duplicates.So for example the key `"and"` might have the list`["then", "best", "then", "after", ...]` listing all the words which cameafter "and" in the text. We'll say that the empty string is what comes beforethe first word in the file.With the mimic dict, it's fairly easy to emit random text that mimics theoriginal. Print a word, then look up what words might come next and pick one atrandom as the next word.Use the empty string as the first word to prime things. If we ever get stuckwith a word that is not in the dict, go back to the empty string to keep thingsmoving.Note: the standard python module 'random' includes arandom.choice(list) method which picks a random elementfrom a non-empty list.For fun, feed your program to itself as input.Could work on getting it to put in linebreaks around 70columns, so the output looks better.<jupyter_code>import random
import sys
def mimic_dict(filename):
    """Returns mimic dict mapping each word to list of words which follow it."""
    #- +++your code here+++
    return
def print_mimic(mimic_dict, word):
    """Given mimic dict and start word, prints 200 random words."""
    #- +++your code here+++
# Provided mimic_file(), calls mimic_dict() and mimic()
def mimic_file(filename):
    dict = mimic_dict(filename)
    print_mimic(dict, '')


# Provided main() implements a argument reading
def main():
    if len(sys.argv) != 2:
        print('usage: ./mimic.py file-to-read')
        sys.exit(1)

    mimic_file(sys.argv[1])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07246998284734134, 'fraction_numerical': 0.006003430531732418, 'mean_word_length': 4.338672768878719, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '391424', 'license': 'Apache-2.0', 'n_tokens_mistral': 643, 'n_tokens_neox': 610, 'n_words': 338, 'path': 'mimic.ipynb', 'repo_name': 'nipraxis/google_mimic', 'size': '2332'}