Contact: aviboots(AT)netvision.net.il
40,772 questions
53,160 answers
573 users
def count_occurrences(lst, n): return lst.count(n) lst = [5, 6, 3, 1, 2, 4, 3, 3, 8, 7, 3, 9, 3] n = 3 print(count_occurrences(lst, n)) ''' run: 5 '''
from collections import Counter lst = [5, 6, 3, 1, 2, 4, 3, 3, 8, 7, 3, 9, 3] n = 3 c = Counter(lst) print(c[n]) print(Counter(lst)[n]) ''' run: 5 5 '''