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 
# naive method 
  
# initializing string 
test_str = "GeeksforGeeks"
  
# using naive method to get count 
# of each element in string 
all_freq = {}
  
for i in test_str:
    if i in all_freq:
        all_freq[i] += 1
    else:
        all_freq[i] = 1
  
# printing result 
print ("Count of all characters in GeeksforGeeks is :
 "
                                        +  str(all_freq))
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #print #freq #char #dict #python
ADD COMMENT
Topic
Name
1+9 =