Skip to content

Instantly share code, notes, and snippets.

@bee-san
Created December 16, 2017 15:29
Show Gist options
  • Select an option

  • Save bee-san/30ef85c97abd62fc93a1d169917edbbe to your computer and use it in GitHub Desktop.

Select an option

Save bee-san/30ef85c97abd62fc93a1d169917edbbe to your computer and use it in GitHub Desktop.
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