list.count()
to count the number of occurrences of val
in lst
.def count_occurrences(lst, val): return lst.count(val)
count_occurrences([1, 1, 2, 1, 2, 3], 1) # 3
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️