How to Multiply All the Items in a Dictionary in Python


This example will teach us how to multiply all the values in a dictionary.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

dict1 = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
total = 1
for i in dict1.keys():
    total *= dict1[i]
print("The result is: ", total)

3. Result

Output:

The result is: 24
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments