Question: Task: Define clean _ record as follows: Clean a ( non - raw ) dictionary record. Input: record - A python dictionary as might be

Task: Define clean_record as follows:
Clean a (non-raw) dictionary record.
Input: record - A python dictionary as might be produced by get_record
Return: cleaned - A copy of record cleaned as explained below, or None if any required keys are missing.
Requirements/steps: The goal of this task is two-fold: 1) Ensure that the record has certain "mandatory" attributes, and 2) simplify the values for certain single-value attributes. More specifically, your function should satisfy these requirements.
*)If the input is missing any of the following keys, return None:['id', 'title', 'year', 'venue', 'abstract'].
*)For the 'id' and 'year' keys, assume there is only one value in the list and convert it into an integer and store this value.
*)if there is a 'refs' key, convert each element of its list to an integer and store this list of integers
*)For any other keys that are present in record, assume there is only one value and store that value as-is (i.e., as a string).
Return the cleaned dictionary.
Example: A correct implementation should produce, for the deml, the following output:
None
{'abstract': 'A mathematical model for communicating sequential processes '
'is given, and a number of its interesting and useful prroperties '
'arestated and proved. The possibilities of nondetermimsm are '
'fullytaken into account.',
'authors': 'S.D,Brookes, C.A.R,Hoare, A.W. Roscoe',
'id': 319,
'refs': [213500.318212,555632],
'title': 'A theory of comm sequential processes',
'venue': 'Journal of the ACM (JACM)',
'year': 1984}
code:
def clean_record(record: dict)-> dict:
####your code###
pprint(clean_record(records[0])) #None!
pprint(clean_record(records[17])) #valid

Step by Step Solution

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!