Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

using python a dictionaries 1 write a function named reverse() that takes as inp

ID: 3836827 • Letter: U

Question

using python a dictionaries 1 write a function named reverse() that takes as input a phone book that is a dictionary mapping names(the keys) to the phones numbers (the values ), the function should return another dictionary representing the reverse phone book mapping phone number (the keys) to the names( the values)...2you would likde to produce a unique dictionary but have a hard time finding the thousands of word that should go into such a dictionary.so write a function scaryDict() that reads an electronic version of scary book , the functions should pick up all the wors in it ,write them in alphabethical order in a new file called dictionary.txt and prints them as well, you can eliminae one or two words because none of them are scary, also use the strip method and the string.punctuaction to eliminate the punctuaction in it. 3) implement function name() that takes no input and repeately ask the user to enter the first bame of the student in the class, when the user enters an empty string , the function should print for every name the numbers of student with that name 4.) you will implement a function index() that takes as input the name of a text file and a list of words. for every word in a list, your function will find the lines in the text file where the words ocurred and print the corresponding line numbers.you should open and read the file once

Explanation / Answer

""" Author: Date :10/3/17 File Name:phone_book.py Description: """ import string def reverse(phone_book): """ This function take the phone book as dictionary and swap the key with value and return new dictionary :param phone_book: this is dictionary like {"name":number} :return: new dictionary of the form {"number":name} """ reversed_phone_book = {} for name in phone_book: reversed_phone_book[phone_book[name]] = name return reversed_phone_book def scaryDict(file_name): """ :param file_name: :return: """ words_dictionary = [] with open(file_name, 'r') as f: for line in f: words = line.strip().split(" ") for word in words: words_dictionary.append(word.strip().translate(None, string.punctuation)) with open("dictionary.txt ", 'w') as f: for word in sorted(words_dictionary): f.write(word + " ") def name(): std_number = 1 std_data = [] while True: first_name = input("Enter student first name: ").strip() if first_name == "": break else: std_data.append((first_name, std_number)) std_number += 1 for x in std_data: print(x[0], x[1]) def index(file_name, words): """ :param file_name: :param words: :return: """ lines = [] with open(file_name) as f: for line in f: lines.append(line.strip()) for word in words: print(word) count = 1 for line in lines: if word in line: print(count, end=" ") print()