Editor

Every Position of a Value

#508 · Lists · Beginner · 25 XP · about 3 min

Write positions(items, value) that returns a list of every index (the position, counting from 0) where value appears in items, from first to last. If value is not in the list at all, return an empty list.

Examples

positions([3, 7, 3, 1, 3], 3)     # returns [0, 2, 4]
positions(['a', 'b', 'c'], 'c')  # returns [2]
positions([1, 2, 3], 9)          # returns []

Note

The items can be numbers or strings, and strings must match exactly: 'A' and 'a' are different.

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.