

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to Multiply All the Items in a Dictionary
When it is required to multiply all the elements in a dictionary, the key values in the dictionary are iterated over. The key is multiplied with the previous key, and output is determined.
The dictionary is a set of key-value pairs.
Example
Below is a demonstration for the same −
my_dict = {'Jane':99,'Will':54,'Mark':-3} my_result = 2 for key in my_dict: my_result = my_result * my_dict[key] print("The reuslt of multiplying keys in a dictionary is : ") print(my_result)
Output
The reuslt of multiplying keys in a dictionary is : -32076
Explanation
- A dictionary is defined.
- A variable is assigned a certain value.
- The ‘key’ in the dictionary is iterated over.
- In every step, this key is multiplied with the variable previously assigned.
- This value is assigned to the same variable itself.
- This is displayed on the console as the output.
- Related Questions & Answers
- Python program to find the sum of all items in a dictionary
- Python program to multiply all numbers in the list?
- C# program to multiply all numbers in the list
- Java Program to select all the items in a JList
- How to print all the keys of a dictionary in Python?
- How to print all the values of a dictionary in Python?
- How to remove all the elements of a dictionary in Python?
- Dictionary Methods in Python (cmp(), len(), items()…)
- Delete items from dictionary while iterating in Python
- Python program to multiply two matrices
- How to access nested Python dictionary items via a list of keys?
- Python - Get items in sorted order from given dictionary
- How to concatenate a Python dictionary to display all the values together?
- How to get a list of all the keys from a Python dictionary?
- How to get a list of all the values from a Python dictionary?
Advertisements