Python Practice › List Programs › Program 40
Remove elements at odd indexes
Write a Python program to remove all elements at odd indexes.
Input
[12, 32, 33, 5, 4, 7, 33]
Output
[12, 33, 4, 33]
Approach
- Keep every second item starting at index 0.
Solution
items = [12, 32, 33, 5, 4, 7, 33]print(items[::2])Output
[12, 33, 4, 33]
Learn the concept
New to this topic? Read the lesson, then come back.