Dictionary Practice - Write Code

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. After you solve each problem, please answer the poll as well.

Finish the function make_dir below which 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}.

Finish the function make_dir below 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}.

Finish the function get_tuple below 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).

Finish the function greater_dict below which takes a dictionary d and an integer cutoff and returns a new 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}.

Finish the get_counts function below 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}.

You have attempted of activities on this page