diff --git a/snippets/count_occurences.md b/snippets/count_occurences.md index f75b24376..f6f8c8269 100644 --- a/snippets/count_occurences.md +++ b/snippets/count_occurences.md @@ -5,11 +5,11 @@ tags: list,beginner 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. +- Use `list.count()` to count the number of occurrences of `val` in `lst`. ```py def count_occurrences(lst, val): - return len([x for x in lst if x == val and type(x) == type(val)]) + return lst.count(val) ``` ```py