Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

count occurrences of character in string python using dictionary

# Python3 code to demonstrate 
# each occurrence frequency using 
# dict.get()
  
# initializing string 
test_str = "GeeksforGeeks"
  
# using dict.get() to get count 
# of each element in string 
res = {}
  
for keys in test_str:
    res[keys] = res.get(keys, 0) + 1
  
# printing result 
print ("Count of all characters in GeeksforGeeks is : 
"
                                             +  str(res))
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #count #occurrences #character #string #python #dictionary
ADD COMMENT
Topic
Name
5+7 =