Dictionary Practice - Parsons Problems¶
Try to solve the following mixed up code problems. You can use the “Help Me” button to make the problem easier if you have made at least three attempts to solve the problem.
Put the blocks in order to define the function make_dir
that takes two lists (l1
and l2
) of equal length and returns a dictionary where the items in l1
are the keys and the items in l2
are the values. For example, make_dir([‘a’, ‘c’], [5, 0])
returns {‘a’: 5, ‘c’: 0}
.
Put the blocks in order to define the function make_dir
which takes a list of tuples (tuple_list
) and returns a dictionary where the first item in each tuple is the key and the second is the value. For example, make_dir([(‘gray’, -3), (‘blue’, 2)])
returns {‘gray’: -3, ‘blue’: 2}
.
Put the blocks in order to define the function get_tuple
which takes a dictionary dict
and a key
and if the key
is found in the dictionary it returns (key, value)
otherwise it returns (key, ‘Not Found’)
. For example, get_tuple({‘a’: 0}, ‘c’)
returns (‘c’, ‘Not Found’)
, and get_tuple({‘a’: 0}, ‘a’)
returns (‘a’, 0)
Put the blocks in order to define the function greater_dictionary
which takes a dictionary d
and an integer cutoff
and returns a dictionary
that contains only the key-value pairs where the value is greater than
or equal to the cutoff. For example, greater_dict({‘a’: 20, ‘b’: 10}, 15)
returns {‘a’: 20}
.
Put the blocks in order to define the function get_counts
which takes a list of strings s_list
and returns a dictionary that has the number of times each unique string appears in the list. For example, get_counts([‘a’,’b’,’a’])
returns {‘a’:2, ‘b’:1}
.