Empty every list value

EasyDictionary Programs · 61 of 94

Write a Python program to clear the list values in a dictionary.

Advertisement
Input
{"virat": [50, 30], "rohit": [40, 10]}
Output
{'virat': [], 'rohit': []}

Approach

  1. clear() each list in place.

Solution

Python
d = {"virat": [50, 30], "rohit": [40, 10]}for v in d.values():    v.clear()print(d)
Output
{'virat': [], 'rohit': []}
Advertisement

Learn the concept

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

More dictionary programs

← All 94 Dictionary Programs