Python program to drop empty Items from a given dictionary.

In this python dictionary program, we will drop empty Items from a given dictionary.

Steps to solve the program
  1. Take a dictionary as input and create an empty dictionary.
  2. Using a for loop and an if-else statement add the key-value pairs from the input dictionary whose value is not empty to the empty dictionary.
  3. Print the output.
				
					dict1 = {"m1":40,"m2":50,"m3":None}
dict2 = {}
for key,val in dict1.items():
    if val != None:
        dict2[key] = val
        
dict2
				
			

Output :

				
					{'m1': 40, 'm2': 50}
				
			

create a dictionary of keys a, b, and c where each key has as value a list from 1-5, 6-10, and 11-15 respectively. 

filter a dictionary based on values.

Leave a Comment