Python Practice › Dictionary Programs › Program 61
Empty every list value
Write a Python program to clear the list values in a dictionary.
Input
{"virat": [50, 30], "rohit": [40, 10]}Output
{'virat': [], 'rohit': []}Approach
clear()each list in place.
Solution
d = {"virat": [50, 30], "rohit": [40, 10]}for v in d.values(): v.clear()print(d)Output
{'virat': [], 'rohit': []}Learn the concept
New to this topic? Read the lesson, then come back.