Files
30-seconds-of-code/snippets/count_occurences.md
Isabelle Viktoria Maciohsek 88dceb260a Update count_occurences.md
2020-10-11 10:29:24 +03:00

298 B

title, tags
title tags
count_occurences list,beginner

Counts the occurrences of a value in a list.

  • Use 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