Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

count similar values in list python

MyList = ["a", "b", "a", "c", "c", "a", "c"]

return my_dict = {i:MyList.count(i) for i in MyList}
# returns :
{'a': 3, 'c': 3, 'b': 1}
 # OR
from collections import Counter
return my_dict = dict(Counter(MyList))
# returns :   
{'a': 3, 'c': 3, 'b': 1}
# the both returns the same so it's up to you to choose the one you prefere ;)
Comment

PREVIOUS NEXT
Code Example
Python :: python flatten dict 
Python :: python read entire file as string 
Python :: standardize columns in pandas 
Python :: how to send get request python 
Python :: find root directory of jupyter notebook 
Python :: how to check if an input is a number in python 
Python :: logging python utf-8 
Python :: add x axis label python 
Python :: python console animation 
Python :: display max rows pandas 
Python :: python random string 
Python :: changing dtype of multiple columns to_datetime 
Python :: how to get user location in python 
Python :: how to convert month to number in python 
Python :: pandas groupby count as new column 
Python :: numpy random float array between 0 and 1 
Python :: seaborn pairplot set title 
Python :: Python tkinter window fullscreen with title bar 
Python :: import forms 
Python :: import decisiontreeclassifier 
Python :: how to remove first row of numpy array 
Python :: python year month day hour minute second 
Python :: python fdr correction 
Python :: save image python 
Python :: convert pascal annotation to yolo 
Python :: send dm discord py 
Python :: python roll dice 100 times 
Python :: how to raise a error in python 
Python :: sigmoid function numpy 
Python :: python file basename 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =