Python Practice › List Programs › Program 68

Elements at several indexes

EasyList Programs · 68 of 100

Write a Python program to get the elements at a list of indexes.

Advertisement
Input
[2, 3, 4, 7, 8, 1, 5, 6, 2, 1, 8, 2], indexes [0, 3, 5, 6]
Output
[2, 7, 1, 5]

Approach

  1. Look up each index.

Solution

Python
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.

More list programs

← All 100 List Programs

Leave a Comment