file = open("tokugawa.txt", 'r')
text = file.read()
text
'Japan\'s Tokugawa (or Edo) period, which lasted from 1603 to 1867, would be the final era of traditional Japanese government, culture and society before the Meiji Restoration of 1868 toppled the long-reigning Tokugawa shoguns and propelled the country into the modern era. Tokugawa Ieyasu\'s dynasty of shoguns presided over 250 years of peace and prosperity in Japan, including the rise of a new merchant class and increasing urbanization. To guard against external influence, they also worked to close off Japanese society from Westernizing influences, particularly Christianity. But with the Tokugawa shogunate growing increasingly weak by the mid-19th century, two powerful clans joined forces in early 1868 to seize power as part of an "imperial restoration" named for Emperor Meiji. The Meiji Restoration spelled the beginning of the end for feudalism in Japan, and would lead to the emergence of modern Japanese culture, politics and society.'
occurrences = {}
for word in text.split():
occurrences[word] = occurrences.get(word, 0) + 1
for word in occurrences:
print("The word", word, "occurs", occurrences[word], "times in the string")
The word Japan's occurs 1 times in the string The word Tokugawa occurs 4 times in the string The word (or occurs 1 times in the string The word Edo) occurs 1 times in the string The word period, occurs 1 times in the string The word which occurs 1 times in the string The word lasted occurs 1 times in the string The word from occurs 2 times in the string The word 1603 occurs 1 times in the string The word to occurs 4 times in the string The word 1867, occurs 1 times in the string The word would occurs 2 times in the string The word be occurs 1 times in the string The word the occurs 11 times in the string The word final occurs 1 times in the string The word era occurs 1 times in the string The word of occurs 8 times in the string The word traditional occurs 1 times in the string The word Japanese occurs 3 times in the string The word government, occurs 1 times in the string The word culture occurs 1 times in the string The word and occurs 6 times in the string The word society occurs 2 times in the string The word before occurs 1 times in the string The word Meiji occurs 2 times in the string The word Restoration occurs 2 times in the string The word 1868 occurs 2 times in the string The word toppled occurs 1 times in the string The word long-reigning occurs 1 times in the string The word shoguns occurs 2 times in the string The word propelled occurs 1 times in the string The word country occurs 1 times in the string The word into occurs 1 times in the string The word modern occurs 2 times in the string The word era. occurs 1 times in the string The word Ieyasu's occurs 1 times in the string The word dynasty occurs 1 times in the string The word presided occurs 1 times in the string The word over occurs 1 times in the string The word 250 occurs 1 times in the string The word years occurs 1 times in the string The word peace occurs 1 times in the string The word prosperity occurs 1 times in the string The word in occurs 3 times in the string The word Japan, occurs 2 times in the string The word including occurs 1 times in the string The word rise occurs 1 times in the string The word a occurs 1 times in the string The word new occurs 1 times in the string The word merchant occurs 1 times in the string The word class occurs 1 times in the string The word increasing occurs 1 times in the string The word urbanization. occurs 1 times in the string The word To occurs 1 times in the string The word guard occurs 1 times in the string The word against occurs 1 times in the string The word external occurs 1 times in the string The word influence, occurs 1 times in the string The word they occurs 1 times in the string The word also occurs 1 times in the string The word worked occurs 1 times in the string The word close occurs 1 times in the string The word off occurs 1 times in the string The word Westernizing occurs 1 times in the string The word influences, occurs 1 times in the string The word particularly occurs 1 times in the string The word Christianity. occurs 1 times in the string The word But occurs 1 times in the string The word with occurs 1 times in the string The word shogunate occurs 1 times in the string The word growing occurs 1 times in the string The word increasingly occurs 1 times in the string The word weak occurs 1 times in the string The word by occurs 1 times in the string The word mid-19th occurs 1 times in the string The word century, occurs 1 times in the string The word two occurs 1 times in the string The word powerful occurs 1 times in the string The word clans occurs 1 times in the string The word joined occurs 1 times in the string The word forces occurs 1 times in the string The word early occurs 1 times in the string The word seize occurs 1 times in the string The word power occurs 1 times in the string The word as occurs 1 times in the string The word part occurs 1 times in the string The word an occurs 1 times in the string The word "imperial occurs 1 times in the string The word restoration" occurs 1 times in the string The word named occurs 1 times in the string The word for occurs 2 times in the string The word Emperor occurs 1 times in the string The word Meiji. occurs 1 times in the string The word The occurs 1 times in the string The word spelled occurs 1 times in the string The word beginning occurs 1 times in the string The word end occurs 1 times in the string The word feudalism occurs 1 times in the string The word lead occurs 1 times in the string The word emergence occurs 1 times in the string The word culture, occurs 1 times in the string The word politics occurs 1 times in the string The word society. occurs 1 times in the string