When accumulating scores by filename and subject, create each subject’s list only when needed, then append the score: scores[filename].setdefault(subject, []).append(score). The method preserves an existing list and supplies the default only for a missing key. section 6.23
Build nested score lists
For each parsed result, use the filename as the outer key and the subject as the inner key. Calling setdefault avoids a separate membership test before appending scores. section 6.23
scores[filename][subject]
Inspect the nested lookup expression used to reach the list for a particular filename and subject. section 6.23
if k not in d:
d[k] = v
Compare setdefault with its explicit equivalent: test whether the key exists, assign the default when absent, and then use the value. section 6.23

