Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to print the freq of each char by using dict in python

# 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: #print #freq #char #dict #python
ADD COMMENT
Topic
Name
4+5 =