In this python dictionary program, we will remove keys with values greater than n.
Steps to solve the program
- Take a dictionary and n as input and create an empty dictionary.
- Use for loop to iterate over keys and values of the input dictionary.
- If the value is less than 6 then add such key-value pairs to the empty dictionary.
- 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}