Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

counter method in python

Counter({'x': 4, 'y': 2, 'z': 2})
Comment

counter method in python

Counter({'o': 3, ' ': 3, 'u': 3, 'e': 2, 'l': 2, 't': 2, 'r': 2, '9': 2, 'W': 1,
 'c': 1, 'm': 1, 'G': 1, 'T': 1, 'i': 1, 'a': 1, 's': 1, '!': 1})
Comment

Counter() Function

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
Comment

counter method in python

from collections import Counter
my_str = "Welcome to Guru99 Tutorials!"
print(Counter(my_str))
Comment

PREVIOUS NEXT
Code Example
Python :: convolution operation pytorch 
Python :: matplotlib multiple bar plot 
Python :: timedelta format python 
Python :: upload file setup django url 
Python :: discord bot python get message id 
Python :: linkedlist python 
Python :: delete file in django terminal 
Python :: request foucus tkinter widget 
Python :: join multiple excel files with python 
Python :: how to import data in python 
Python :: Removing Elements from Python Dictionary Using popitem() method 
Python :: replace in python 
Python :: pandas get size of each group 
Python :: datetime conversion 
Python :: extend python 
Python :: child class in python 
Python :: python ignore first value in generator 
Python :: pandas save dataframe with list 
Python :: daraja mpesa 
Python :: how to standardize the image data to have values between 0 and 1 
Python :: python rounding numbers to n digits 
Python :: vector data 
Python :: Yield Expressions in python 
Python :: download gzip file python 
Python :: python list to arguments 
Python :: python declare 2d list 
Python :: instance of object 
Python :: generating random numbers numpy 
Python :: pycryptodome rsa encrypt 
Python :: python return multiple value from a function 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =