Python Practice › List Programs › Program 25

Remove by index with pop()

EasyList Programs · 25 of 100

Write a Python program to remove an element at a given index with pop().

Advertisement
Input
["a", "b", "c", "d"], index 2
Output
c ['a', 'b', 'd']

Approach

  1. pop(index) removes and returns the item.

Solution

Python
items = ["a", "b", "c", "d"]removed = items.pop(2)print(removed, items)
Output
c ['a', 'b', 'd']

Learn the concept

New to this topic? Read the lesson, then come back.

More list programs

← All 100 List Programs

Leave a Comment