Skip to content

Instantly share code, notes, and snippets.

@dmoneyballer
Created August 21, 2019 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmoneyballer/dabb75b9471d5d4acd03f20d2e6041c0 to your computer and use it in GitHub Desktop.
Save dmoneyballer/dabb75b9471d5d4acd03f20d2e6041c0 to your computer and use it in GitHub Desktop.
# Put your code here
from collections import OrderedDict
with open('test.txt', 'w') as e:
e.write("""I DO NOT LIKE THEM IN A HOUSE
I DO NOT LIKE THEM WITH A MOUSE
I DO NOT LIKE THEM HERE OR THERE
I DO NOT LIKE THEM ANYWHERE
I DO NOT LIKE GREEN EGGS AND HAM
I DO NOT LIKE THEM SAM I AM """)
start = input('Enter the input file name:')
words = OrderedDict()
with open(start, 'r') as f:
for line in f:
wordz = line.split()
for word in wordz:
if word in words.keys():
words[word] = words[word] + 1
else:
words[word] = 1
for w, c in words.items():
print(w, c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment