Python: Replace dictionary values with their average
37. Replace Dictionary Values with Their Sums
Write a Python program to replace dictionary values with their sums.
Visual Presentation:
Sample Solution:
Python Code:
Sample Output:
[{'subject': 'math', 'id': 1, 'V+VI': 76.0}, {'subject': 'math', 'id': 2, 'V+VI': 73.5}, {'subject': 'math', ' id': 3, 'V+VI': 80.5}]
For more Practice: Solve these Related Problems:
- Write a Python program to update a dictionary so that each key's value becomes the sum of its original value and another corresponding value from a second dictionary.
- Write a Python program to iterate over a dictionary and replace each value with the sum of the digits of that value.
- Write a Python program to merge a dictionary with itself by summing values that share the same key after a transformation.
- Write a Python program to implement a function that takes a dictionary and returns a new dictionary with each value replaced by its cumulative sum with other values.
Go to:
Previous: Write a Python program to create a dictionary from two lists without losing duplicate values.
Next: Write a Python program to match key values in two dictionaries.
Python Code Editor:
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.