[Solved] SOLVED:Analyze a text file to produce

$25

File Name: SOLVED:Analyze_a_text_file_to_produce.zip
File Size: 348.54 KB

SKU: [Solved] SOLVED:Analyze a text file to produce Category: Tag:
5/5 - (1 vote)

# Analyze a text file to produce# a list of words (in alphabetical order) with their frequencies# a list of letters (also in alphabetical order) with their frequencies## Words will all be converted to lower case and have any puncutation# marks removed.# ***** function takes a word as input and returns# ***** as lower case with all punctuation removed.## *****: convert the word to lower case.# ***** through the word one character at a time, and if it is# ***** a-z, add it to a new word.def lower_letters_only(word):lower_word = word = word.lower()for letter in word:if letter in abcdefghijklmnopqrstuvwxyz:lower_word+= letterreturn lower_word# This function will repeatedly ask for a file name# and return a file object when it is able to successfully# open the file. Hint: use try/except and use a boolean variable# such as valid_file to indicate whether you had a valid file or not.def get_input_file(fn): #fn file namewhile True:print(enter + file_type + filename: )filename = input()print(filename)try:with open(filename, r) as f:my_file = f.read()return my_fileexcept FileNotFoundError:print(No such file. Check file name and path and try again.)except IOError:print(File does not exist)pass## This function will take as its input a dictionary# and will print the contents with the keys in alphabetical# order. For example, {cat: 3, ant:4, bee: 7} will print as## ant 4# bee 7# cat 3## Hint: use list(d.keys()) to get all the dictionary keys as a list.def display_dictionary(d):new_list = []for element in d.keys():new_list.append(element)new_list.sort()for element in new_list:print(element, d[element])pass############# ***** program begins here# ***** an empty dictionary for the wordswords = { }# ***** an empty dictionary for the lettersletters = { }# Get the input filewith open(words.txt,r) as f:# Read the file one line at a time, and:for line in f:for word in line.split():print(word)# split it into words# for each word:# convert to lowercase and remove punctuation# go through it letter by letter (hint: use for in range(),# updating the letter count in the letters dictionaryfor word in len in range(word):# Close the input filef.close()# display the words dictionaryprint(words)# display the letters dictionaryprint(letters)

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] SOLVED:Analyze a text file to produce
$25