Reputation: 2567
I want to part of a script to be something like this.
if list[1] is in list.pop n times:
return True
Upvotes: 0
Views: 467
Reputation: 8610
Or you can use Counter
:
>>> from collections import Counter
>>> Counter([1, 2, 3, 1, 1])
Counter({1: 3, 2: 1, 3: 1})
>>>
This is good if you want to get all the counts of the distinct elements in the list one time.
Upvotes: 2
Reputation: 113905
Number of items in a list:
len(myList)
Number of times the i
th element occurs in a list:
myList.count(mylist[i])
Upvotes: 2
Reputation: 10003
Simply use:
list.count(element)
Example:
>>> [1,2,3,4,2,1].count(1)
2
Upvotes: 7