Remove a dictionary from a list

EasyDictionary Programs · 59 of 94

Write a Python program to remove the 4th dictionary from a list.

Advertisement
Input
[{"t20": 50, "odi": 70}, {"t20": 40, "odi": 10}, {"t20": 30, "odi": 0}, {"t20": 45, "odi": 65}]
Output
[{'t20': 50, 'odi': 70}, {'t20': 40, 'odi': 10}, {'t20': 30, 'odi': 0}]

Approach

  1. pop(3).

Solution

Python
data = [{"t20": 50, "odi": 70}, {"t20": 40, "odi": 10}, {"t20": 30, "odi": 0}, {"t20": 45, "odi": 65}]data.pop(3)print(data)
Output
[{'t20': 50, 'odi': 70}, {'t20': 40, 'odi': 10}, {'t20': 30, 'odi': 0}]
Advertisement

Learn the concept

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

More dictionary programs

← All 94 Dictionary Programs