Forbidden:
Your program may not use any techniques or Python features
forbidden below. Do not use the following list-related
functionality:
Do not use any string methods other than lower.
Do not "import" any functionality into your code.
Do not use list slicing.
Do not use any techniques not covered in class.
You may use the list's append method.
def keep_first(dictionaries):
The function keep_first takes a list of dictionaries as a
parameter. The dictionaries in the list have three keys: "First
Name", "Last Name", and "GPA".
The function transforms that list into a dictionary that uses a
two-valued tuple as a key. The key is composed of the first and
last names found in one of the dictionaries. The associated value
will be the GPA.
Any First/Last key without an associated GPA should be
ignored.
If a First/Last key with a GPA is seen more than once, the first
occurrence should be used.
assert keep_first(
[
{"First Name": "Alice", "Last Name": "Smith", "GPA": 4.0},
{"First Name": "Bob", "Last Name": "Jones", "GPA": 3.0},
{"First Name": "Charlie", "Last Name": "Brown", "GPA": 2.0},
]
) == {
("Alice", "Smith"): 4.0,
("Bob", "Jones"): 3.0,
("Charlie", "Brown"): 2.0,
}
assert keep_first(
[
{"First Name": "Alice", "Last Name": "Smith", "GPA": 4.0},
{"First Name": "Bob", "Last Name": "Jones"},
{"First Name": "Alice", "Last Name": "Smith", "GPA": 2.0},
]
) == {
("Alice", "Smith"): 4.0,
}