Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- """filename: wordy.py"""
- sample_file = open("sample.txt", "r")
- words = sample_file.read().split()
- count_and_word = {}
- for word in words:
- word = word.replace(".","").replace("(", "").replace(")", "").replace(",", "").lower()
- if word not in count_and_word:
- count_and_word[word] = 1
- else:
- count_and_word[word] += 1
- for word in sorted(count_and_word.keys()):
- print "{0}: {1}".format(count_and_word[word], word)
Advertisement
Add Comment
Please, Sign In to add comment