HOW TO COUNT THE FREQUENCY OF EACH CHARCTER IN STRING


example:

input:
     " itspythonand"
output:

     {'y': 1, 'd': 1, 'o': 1, 'i': 1, 't': 2, 'h': 1, 'n': 2, 'a': 1, 's': 1, 'p': 1}


p=input()      #taking string input from user
s=set(p)     #set is a collection of unique elements
d={}          #an empty dictionary
for i in s:
    c=0
    for j in range(len(p)):
        if i==p[j]:
            c+=1
    d[i]=c
print(d)

Comments