Skip to content

Home

Count occurrences

Counts the occurrences of a value in a list.

def count_occurrences(lst, val):
  return lst.count(val)

count_occurrences([1, 1, 2, 1, 2, 3], 1) # 3

More like this

Start typing a keyphrase to see matching snippets.