Introduction
Dictionary basics
Dictionaries in loops and conditional statements
Dictionaries in functions
13. Modifying dictionaries in functions
Summary

Instruction

Amazing! When using dictionaries in functions, remember the following: if you modify a dictionary inside a function, this modification will be applied to your dictionary outside the function as well.

def zero_negative(dictionary_to_check):
  for key in dictionary_to_check.keys():
    if dictionary_to_check[key] < 0:
      dictionary_to_check[key] = 0

In the function above, we modify the original dictionary, so any changes inside will affect the dictionary passed in as the argument.

Exercise

Write a function named add_ten() that takes a dictionary whose values are numbers. The function should add 10 to every even value in the dictionary.

Stuck? Here's a hint!

Use the following condition to check if a given dictionary value is even:

if dictionary[key] % 2 == 0: