Menu
support@nursinghomework.org
+1 714-215-3097

(Solved) : Write Function Called Lettercount Filename Accepts Single Parameter Containing Name File F Q35630309

can any1 use simple python way. i just start it Write a function called letter_count(filename) that accepts a single parameter containing the name of a file. Your function sFor example: Test Input Result letter_count (test1.txt Contents of test1.txt: a 1 e: 4 A simple file with only one line h1

Write a function called letter_count(filename) that accepts a single parameter containing the name of a file. Your function should read the contents of the text file, and calculate the number of times each English letter appears in the file. The function should print a list of (character: count) pairs to the standard output. You may define additional “helper” functions as you wish. Any character that is not an English letter should be ignored. The case should be ignored (so both ‘a’ and ‘A’ count as the letter ‘a’). Report the output with lower case letters. The letters should be sorted into standard alphabetical order and should be printed in the format letter, then a space, then a colon, then a space, then the frequency. If a letter is not present in the file, then it should not be printed. E.g a 6 b:3 d :2 A student who completes this exercise should be able to: Read the contents of a text file Use a dictionary to store keys and values Sort dictionary keys For example: Test Result letter_count (‘testl.txt) Contents of ‘testl.txt’: a 1 A simple file with only one line e4 h1 1:4 o2 For example: Test Input Result letter_count (‘test1.txt Contents of ‘test1.txt’: a 1 e: 4 A simple file with only one line h1 i:4 1:4 m1 n3 o 2 p 1 w1 y 1 letter_count (‘test2.txt’) Contents of ‘test2.txt’ a1 e3 f: 2 h2 This file has five lines 12 n1 s3 Show transcribed image text Write a function called letter_count(filename) that accepts a single parameter containing the name of a file. Your function should read the contents of the text file, and calculate the number of times each English letter appears in the file. The function should print a list of (character: count) pairs to the standard output. You may define additional “helper” functions as you wish. Any character that is not an English letter should be ignored. The case should be ignored (so both ‘a’ and ‘A’ count as the letter ‘a’). Report the output with lower case letters. The letters should be sorted into standard alphabetical order and should be printed in the format letter, then a space, then a colon, then a space, then the frequency. If a letter is not present in the file, then it should not be printed. E.g a 6 b:3 d :2 A student who completes this exercise should be able to: Read the contents of a text file Use a dictionary to store keys and values Sort dictionary keys For example: Test Result letter_count (‘testl.txt) Contents of ‘testl.txt’: a 1 A simple file with only one line e4 h1 1:4 o2
For example: Test Input Result letter_count (‘test1.txt Contents of ‘test1.txt’: a 1 e: 4 A simple file with only one line h1 i:4 1:4 m1 n3 o 2 p 1 w1 y 1 letter_count (‘test2.txt’) Contents of ‘test2.txt’ a1 e3 f: 2 h2 This file has five lines 12 n1 s3

Leave a Reply

Your email address will not be published. Required fields are marked *