Answer to Question #265935 in Python for H A

Question #265935

Write a program that reads a string and returns a table of the letters of the alphabet in

alphabetical order which occur in the string together with the number of times each letter

occurs. Case should be ignored. A sample output of the program when the user enters the data

“ThiS is String with Upper and lower case Letters”, would look this this:


a  2
c  1
d  1
e  5
g  1
h  2
i  4
l  2
n  2
o  1
p  2
r  4
s  5
t  5
u  1
w  2
1
Expert's answer
2021-11-15T00:22:53-0500
def count_all(text):
    text = "".join(text.strip(".").split()).lower()
    counts = {}
    for char in text:
        if char not in counts:
            counts.setdefault(char,1)
        else:
            counts[char] = counts[char] + 1
    counts = sorted(counts.items())
    for i in counts:
        print(i[0],' ',i[1])



count_all('ThiS is String with Upper and lower case Letters')

a   2
c   1
d   1
e   5
g   1
h   2
i   4
l   2
n   2
o   1
p   2
r   4
s   5
t   5
u   1
w   2

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS