Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

How to check the number of occurence of each character of a given string in python

c = Counter("thiiss wiill caalcullateeee theee numbeeer of characters")

# now when we print c, it will have the following data:

Counter({'e': 11, ' ': 6, 'l': 5, 'a': 5, 't': 4, 'i': 4, 'c': 4, 'h': 3, 's': 3, 'r': 3, 'u': 2, 'w': 1, 'n': 1, 'm': 1, 'b': 1, 'o': 1, 'f': 1})

# And now we can check the occurrence of each of the characters as follows:

count_e = c.get('e') # returns 11
Source by python.plainenglish.io #
 
PREVIOUS NEXT
Tagged: #How #check #number #occurence #character #string #python
ADD COMMENT
Topic
Name
6+3 =