Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

count frequency of characters in string

#count the frequency of a character in a string using a dictionary
s=input("enter string: ")
a={}
for i in s:
    if i not in a:
        a[i]=s.count(i)
    else:
        pass
print("frequency")
for ch in a:
    print(ch,a[ch])
#output
enter string: hello world
frequency
h 1
e 1
l 3
o 2
  1
w 1
r 1
d 1
 
PREVIOUS NEXT
Tagged: #count #frequency #characters #string
ADD COMMENT
Topic
Name
8+1 =