Why is not KeyError if word wasn't in data?

Really can’t understand why is 0 here. How was the word Astronomy appeared at all in vocab, if it doesn’t exist?


H

Hey @someone555777,
Please note that vocab is initialized as a defaultdict instead of dict. One of the key properties for the former is that it never returns a “Key Error”. You can read more about it here. Let us know if this helps you.

Cheers,
Elemento

1 Like