easy +5 pts

Keep only even indexes

Extract every element at an even index from a list.

Write a function `keep_even_indexes(lst)` that takes a list `lst` and returns a new list containing only the elements at even indices (0, 2, 4, ...). The original list should not be modified.

Constraints

The input list can be empty or contain any number of elements. The elements can be of any type (integers, strings, etc.). The function should work in O(n) time and O(n) space (where n is the length of the input list).

Example

>>> keep_even_indexes([0, 1, 2, 3, 4, 5])
[0, 2, 4]
>>> keep_even_indexes(['a', 'b', 'c', 'd'])
['a', 'c']
>>> keep_even_indexes([])
[]
5 points ~5 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use list slicing with a step of 2.
Remember that indices are 0-based.
Even indices are 0, 2, 4, and so on.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.