Count Occurrences of Each Element in List in Python | Counter() Constructor of collections Module

preview_player
Показать описание
Python code of this video:

my_list = ['red', 'blue', 'red', 'green', 'orange', 'blue', 'green', 'yellow', 'purple', 'blue']
print(my_list)

from collections import Counter

Counter(my_list)

import pandas as pd

pd.Series(my_list).value_counts()

def counts(a):
dic = {}
for j in a:
if j in dic:
dic[j] +=1
else:
dic[j] =1
return dic

counts(my_list)

Follow me on Social Media:

Рекомендации по теме
welcome to shbcf.ru