Complete the function getLetterFrequency() to return a list containing the number of times each letter of the alphabet occurs in the string passed to it. The Oth index corresponds to the letter "a" or...


In python programming language.


Complete the function getLetterFrequency() to return<br>a list containing the number of times each letter of the<br>alphabet occurs in the string passed to it. The Oth<br>index corresponds to the letter

Extracted text: Complete the function getLetterFrequency() to return a list containing the number of times each letter of the alphabet occurs in the string passed to it. The Oth index corresponds to the letter "a" or "A", the 1st corresponds to the letter "b" or "B", ..., the 25th corresponds to "z" or "Z". You should ignore any non-alphabet characters that occur in the string. But make sure that both lowercase and uppercase letters contribute to the same count. You must use the ord() function to convert letters into indexed based values. Note that you can offset a number by ord("a") or ord("A") to get the index that you need. You should use at least some of the (or all of) following string methods: • isalpha() lower() • upper() • isupper() • islower() and the following string functions: ord() len()
Count all the letters in a sentence. Both A and a should count for the same letter.<br>The best way to get an indexed letter value is subtract ord(

Extracted text: Count all the letters in a sentence. Both A and a should count for the same letter. The best way to get an indexed letter value is subtract ord("a") or ord("A") from your current letter. String methods: isalpha(), lower(), upper(), islower(), isupper() String functions: ord(), len() def getLetterFrequency(sentence): freq = [] for i in range(26): %3D freq.append(0) # TODO: count each letter here return freq print(getLetterFrequency("Hello World")) print("Testing") assert( getLetterFrequency("Hello World!") == [0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 3, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0]) assert( getLetterFrequency("Wow, such tricky...") == [0, 0, 2, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 2, 0, 1, 0]) assert( getLetterFrequency("The quick brown fox jumps over the lazy dog.") == [1, 1, 1, 1, 3, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 1, 1, 2, 1, 2, 2, 1, 1, 1, 1, 1]) print("Done!") 5. Expected Output Example, the string "Hello World" returns list: [0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 3, 0, 0, 2, 0, 0,1, 0, 0, 0, 0, 1, 0, 0, 0]
Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here