Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

How to Count occurrences of an item in a list in python

from collections import Counter

1ist1 = ['Peter', 'Rose', 'Donald', 'Peter']
a = Counter(listl).get('Peter')

print(f'Peter appears in the list {a} times')

# Output:
# Peter appears in the list 2 times
Source by www.kite.com #
 
PREVIOUS NEXT
Tagged: #How #Count #occurrences #item #list #python
ADD COMMENT
Topic
Name
1+5 =