Python Practice › List Programs › Program 68
Elements at several indexes
Write a Python program to get the elements at a list of indexes.
Input
[2, 3, 4, 7, 8, 1, 5, 6, 2, 1, 8, 2], indexes [0, 3, 5, 6]
Output
[2, 7, 1, 5]
Approach
- Look up each index.
Solution
items = [2, 3, 4, 7, 8, 1, 5, 6, 2, 1, 8, 2]indexes = [0, 3, 5, 6]print([items[i] for i in indexes])Output
[2, 7, 1, 5]
Learn the concept
New to this topic? Read the lesson, then come back.