Python para impacientes

Python como usar o count_occurences

January 04, 2020

Counts the occurrences of a value in a list.

Increment a counter for every item in the list that has the given value and is of the same type.

def count_occurrences(lst, val):
  return len([x for x in lst if x == val and type(x) == type(val)])
count_occurrences([1, 1, 2, 1, 2, 3], 1) # 3

Acesse a Referência original 1: Acesse a Referência original 2: