Program to remove keys with values greater than n.

In this python dictionary program, we will remove keys with values greater than n.

Steps to solve the program
  1. Take a dictionary and n as input and create an empty dictionary.
  2. Use for loop to iterate over keys and values of the input dictionary.
  3. If the value is less than 6 then add such key-value pairs to the empty dictionary.
  4. Print the output.
				
					A =  {'sqa':3,'tools':5,'python':7}
B = {}

for k,v in A.items():
    if v < 6:
        B[k] = v
        
print(B)
				
			

Output :

				
					{'sqa': 3, 'tools': 5}
				
			

extract key’s value if key is present in list and dictionary

remove keys with substring values.

Leave a Comment