The code is excerpted from Natural Language Processing with Python, page 119. Frequency of modals in different sections of the Brown Corpus. My issue turns out to be that it