Iterating Over a Dictionary A dictionary is an iterable object and so a for loop can be
Fantastic news! We've Found the answer you've been seeking!
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. 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']
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date: