Even Keys || Python
Even Keys
Next, we are going to do something similar, but we are going to use the keys in order to retrieve the values. Additionally, we are going to only look at every even key within the dictionary. Here are the steps:
Create a function called?sum_even_keys?that takes a dictionary named?my_dictionary, with all integer keys and values, as a parameter. This function should return the sum of the values of all even keys.
Similar to the previous problem, we are iterating through our dictionary, except this time we are iterating through the keys instead of the values. In order to get the keys we use the?keys()?function and to get the value of a key we can use brackets. To test if the key is even we use the modulus operator and test if the remainder is 0 when dividing by 2.