With counts = defaultdict(int), what does counts['new'] return for a key never set before?
Correct answer
C. 0
18 views
C. 0
18 views
defaultdict(int) calls int() to create a default of 0 for missing keys, which makes counting idioms such as counts[word] += 1 work without checks.
Asked in: NTS, Python Developer Interviews
Not sure why the answer is C? Ask here and get an explanation.