Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

PREVIOUS NEXT
Code Example
Python :: python pandas apply function to one column 
Python :: pygame key pressed once 
Python :: concatenate 2 array numpy 
Python :: How to check for palindromes in python 
Python :: delete n from textpython 
Python :: how to select a single cell in a pandas dataframe 
Python :: converting int to binary python 
Python :: add row in db django 
Python :: how to make a venv python 
Python :: how to make a rect in pygame 
Python :: extend a list python 
Python :: python sort dictionary by key 
Python :: django check if user is admin 
Python :: python merge dictionaries 
Python :: multiply each element in list python 
Python :: live plot loss 
Python :: sort a list numbers in python 
Python :: tensorflow_version 
Python :: python env 
Python :: get hash python 
Python :: how to insert item last in list python 
Python :: create limit using matplotlib 
Python :: convert float in datetime python 
Python :: print pattern a shape in python 
Python :: work with gzip 
Python :: drupal 8 request_time 
Python :: python pynput space 
Python :: numpy array length 
Python :: python set timezone of datetime.now 
Python :: pyauto gui save screenshot 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =