Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python count repeated elements in a list

# Basic syntax:
dict_of_counts = {item:your_list.count(item) for item in your_list}

# Example usage:
your_list = ["a", "b", "a", "c", "c", "a", "c"]
dict_of_counts = {item:your_list.count(item) for item in your_list}
print(dict_of_counts)
--> {'a': 3, 'b': 1, 'c': 3}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #count #repeated #elements #list
ADD COMMENT
Topic
Name
1+5 =