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".

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

In python programming language 

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"))
# remove the
when you're ready to rest fully
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,
%3D
%3D
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!")
# remove the
when you're ready to rest fully
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.100.001.0.0.01
Transcribed Image 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")) # remove the when you're ready to rest fully 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, %3D %3D 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!") # remove the when you're ready to rest fully 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.100.001.0.0.01
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()
Transcribed Image 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()
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Introduction to computer system
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education