Blog Archive

search

Tuesday, August 6, 2019

Python program to count the number of characters (character frequency) in a string

a = input('Enter a string : ')
dict = {}
for n in a:
    keys = dict.keys()
    if n in keys:
        dict[n] += 1 # insert value in dict and add count
    else:
        dict[n] = 1
     
print(dict)

No comments:

Post a Comment

Python program to create a string from two given strings concatenating uncommon characters of the said strings

PROGRAM :  a = input('Enter a string : ') b = input('Enter a string : ') c='' for i in a:     if(i not in b):...