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

Python 3.6 Question 13 (20 points) Write a function named initialVowels that ana

ID: 3728737 • Letter: P

Question

Python 3.6

Question 13 (20 points) Write a function named initialVowels that analyzes the contents of a text file for words that begin with a vowel. The letters a, e, i, o and u are vowels. The function initialVowels should return a dictionary of vowel:word-list pairs, Each vowel should be a key in the dictionary if and only if it is the first letter of some word in the input file. The value of a key is a list of all the words in the input file in which that vowel is the first letter. (Hint: your job is easier if you lowercase the text in the input file.) Input. The function initialVowels takes a single parameter: inFile, a string that IS the name of a text file. This file contains only upper and lower case letters and white space (no punctuation marks or other special characters). It is in the current working directorv i. Output, Return a vowel:word-list dictionarv For example, if the file named catInTheHat.txt contains the same text as in Question 12, then the function call print(initialVowels('catInTheHat.txt')) should output 1 'it 1 1 1 all', 'and' ])

Explanation / Answer

def initialVowels(fileName): try: d = dict() f = open(fileName) for line in f: for x in line.split(): if(x[0] in "aeiouAEIOU"): if (x[0] not in d.keys()): d[x[0]] = x else: d[x[0]] = d[x[0]].append(x) f.close() return d except Exception: print("File not found")