Question: Iterating Over a Dictionary A dictionary is an iterable object and so a for loop can be usedto iterate over the entries in a dictionary.

Iterating Over a Dictionary

A dictionary is an iterable object and so a for loop can be usedto iterate over the entries in a dictionary. The loop

for k in dict:    body_code

will iterate over the keys of thedictionary dict setting k in turn to each keyof dict.

Consider a dictionary that has strings as keys and integers asvalues -
e.g.

{'a':24, 'e':30, 't':12, 'n':10}

Write a function big_keys that takes such a dictionaryas the first argument and an integer as the second argument andreturns the list of keys all of whose values are bigger than thesecond argument.

You must use a for loop to iterate over the dictionary.

Example:

>>> big_keys({'a':24, 'e':30, 't':12, 'n':10}, 15)['a', 'e']

Step by Step Solution

3.54 Rating (158 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!