Editor

Count Element

#9 · Lists · Beginner · 40 XP · about 4 min

Write a function called count_element(lst, element) that counts how many times an element appears in a list.

Example

count_element([1, 2, 2, 3, 2], 2)    # Returns 3
count_element(["a", "b", "a"], "a")  # Returns 2
count_element([1, 2, 3], 5)          # Returns 0

Requirements

  • Return the count as an integer
  • Return 0 if element is not found
  • Handle both numbers and strings

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.