Counting missing record values
A list contains dictionary records. Apply these requirements to count_empty(records):
- Count every None value across all records.
- Do not count
0or an empty string; both are recorded values. - Every key is present. Count missing values, not absent keys.
- No variable named
worksheetis defined.
The example in Listing 1 has three missing values. record.values() visits the values stored in one dictionary.
Compare the four implementations in Listing 2.
Which implementation satisfies the stated requirements?
TipHint
record.values()provides the dictionary’s stored values without its keys and leaves it unchanged. An empty dictionary has no values to visit.list(values)collects visited values into a list. Forrecord = {"X": 4, "Y": None},list(record.values())gives[4, None].