How to count the number of repeated items in a list in the Python programming language. More details: [ Ссылка ]
Python code of this video:
my_list = ['a', 'c', 'b', 'a', 'a', 'c'] # Create example list
print(my_list) # Print example list
# ['a', 'c', 'b', 'a', 'a', 'c']
my_list_count1 = {i:my_list.count(i) for i in my_list} # Apply count function
print(my_list_count1) # Print list counts
# {'a': 3, 'c': 2, 'b': 1}
from collections import Counter # Import Counter
my_list_count2 = Counter(my_list) # Apply Counter function
print(my_list_count2) # Print list counts
# Counter({'a': 3, 'c': 2, 'b': 1})
Follow me on Social Media:
Facebook – Statistics Globe Page: [ Ссылка ]
Facebook – R Programming Group for Discussions & Questions: [ Ссылка ]
Facebook – Python Programming Group for Discussions & Questions: [ Ссылка ]
LinkedIn – Statistics Globe Page: [ Ссылка ]
LinkedIn – R Programming Group for Discussions & Questions: [ Ссылка ]
LinkedIn – Python Programming Group for Discussions & Questions: [ Ссылка ]
Twitter: [ Ссылка ]
Music by bensound.com
Ещё видео!