Answer to Question #256945 in Python for Raju

Question #256945

Character Frequency


Write a program to compute the frequency of characters other than space.


Sample Input 1

Pop up

Sample Output 1

o: 1

p: 3

u: 1


1
Expert's answer
2021-10-31T12:09:19-0400
def char_frequency(str1):
    dict1 = {}
    for n in str1:
        temp = n.lower()
        
        keys = dict1.keys()
        if temp in keys:
            
            
            dict1[temp] += 1
        else:
            dict1[temp] = 1
    return dict1
dict2 = char_frequency('Pop up')
for row in dict2:
    print(row, dict2[row])

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