# Python program to find the sum of all items in a dictionary

## Python program to find the sum of all items in a dictionary

Given a dictionary in Python, write a Python program to find the sum of all Items in the dictionary.
Examples:

```Input : {'a': 100, 'b':200, 'c':300}
Output : 600

Input : {'x': 25, 'y':18, 'z':45}
Output : 88```

• Approach #1 : Using Inbuilt sum() Function
Use the sum function to find the sum of dictionary values.
 `# Python3 Program to find sum of` `# all items in a Dictionary` `# Function to print sum` `def` `returnSum(myDict):` `    ` `    ``list` `=` `[]` `    ``for` `i ``in` `myDict:` `        ``list``.append(myDict[i])` `    ``final ``=` `sum``(``list``)` `    ` `    ``return` `final` `# Driver Function` `dict` `=` `{``'a'``: ``100``, ``'b'``:``200``, ``'c'``:``300``}` `print``(``"Sum :"``, returnSum(``dict``))`
• Output:
`Sum : 600`
• Approach #2 : Using For loop to iterate through values using values() function
Iterate through each value of the dictionary using values() function and keep adding it to the sum.
 `# Python3 Program to find sum of` `# all items in a Dictionary` `# Function to print sum` `def` `returnSum(``dict``):` `    ` `     ``sum` `=` `0` `     ``for` `i ``in` `dict``.values():` `           ``sum` `=` `sum` `+` `i` `     ` `     ``return` `sum` `# Driver Function` `dict` `=` `{``'a'``: ``100``, ``'b'``:``200``, ``'c'``:``300``}` `print``(``"Sum :"``, returnSum(``dict``))`
• Output:
`Sum : 600`
 `# Python3 Program to find sum of` `# all items in a Dictionary` `# Function to print sum` `def` `returnSum(``dict``):` `    ` `     ``sum` `=` `0` `     ``for` `i ``in` `myDict:` `           ``sum` `=` `sum` `+` `dict``[i]` `     ` `     ``return` `sum` `# Driver Function` `dict` `=` `{``'a'``: ``100``, ``'b'``:``200``, ``'c'``:``300``}` `print``(``"Sum :"``, returnSum(``dict``))`
• Output:
`Sum : 600`

Last Updated on March 17, 2022 by admin

## Pandas Series.str.strip(), lstrip() and rstrip()Pandas Series.str.strip(), lstrip() and rstrip()

Python | Pandas Series.str.strip(), lstrip() and rstrip() Python is a great language for doing data

## Python program to read character by character from a filePython program to read character by character from a file

Python program to read character by character from a file Given a text file. The

## Triple Quotes in PythonTriple Quotes in Python

Triple Quotes in Python Spanning strings over multiple lines can be done using python’s triple

## Python program to get all subsets of given size of a setPython program to get all subsets of given size of a set

Python program to get all subsets of given size of a set Given a set,

## Python program to get all unique combinations of two ListsPython program to get all unique combinations of two Lists

Python program to get all unique combinations of two Lists The combination is a mathematical

## break, continue and pass in Pythonbreak, continue and pass in Python

break, continue and pass in Python Using loops in Python automates and repeats the tasks

## How to save a Python Dictionary to a CSV File?How to save a Python Dictionary to a CSV File?

How to save a Python Dictionary to a CSV File? CSV (comma-separated values) files are one

## How to get file size in Python?How to get file size in Python?

How to get file size in Python? We can follow different approaches to get the