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
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])
Comments
Leave a comment