Created
December 16, 2017 15:29
-
-
Save bee-san/30ef85c97abd62fc93a1d169917edbbe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def make_Dictionary(train_dir): | |
| # where train_dir is the directory of the emails | |
| emails = [os.path.join(train_dir,f) for f in os.listdir(train_dir)] | |
| all_words = [] | |
| for mail in emails: | |
| with open(mail) as m: | |
| for i, line in enumerate(m): | |
| if i == 2: # Body of email is only 3rd line of text file | |
| words = line.split() | |
| all_words += words | |
| dictionary = Counter(all_words) | |
| return dictionary |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment