Find the product of all items in the dictionary.

In this python dictionary program, we will find the product of all items in the dictionary.

Steps to solve the program
  1. Take a dictionary as input and create a variable and assign its value equal to 1.
  2. Use for loop to iterate over values in the dictionary using values().
  3. During iteration multiply the value by the variable that we have created.
  4. Print the output.
				
					dict1 =  {'a':2,'b':4,'c':5}
result = 1

for val in dict1.values():
    result *= val
    
print(result)
				
			

Output :

				
					40
				
			

create a dictionary where keys are between 1 to 5 and values are squares of the keys.

remove a key from the dictionary.

Leave a Comment