Skip to content

Instantly share code, notes, and snippets.

@rmporsch
Last active January 18, 2017 08:24
Show Gist options
  • Save rmporsch/667030ff309978457d37d943ab52d8ef to your computer and use it in GitHub Desktop.
Save rmporsch/667030ff309978457d37d943ab52d8ef to your computer and use it in GitHub Desktop.
transforms emails from Dictionary.com to table formatted entries
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
newEntry = False
words = []
defs = []
definition = []
with open("dict.email", 'r') as f:
for line in f:
if re.search(re.escape("\\"), line):
words.append(re.sub(
(re.escape("\\")+".*"+re.escape("\\")),
"",
line.strip("\\n")))
newEntry = True
elif re.search("[0-9]\. ", line):
definition.append(line.strip("\\n"))
elif re.search("^noun$", line):
definition.append(line)
elif re.search("^verb$", line):
definition.append(line.strip("\\n"))
elif re.search("Quotes", line):
newEntry = False
defs.append("".join(definition))
definition = []
dat = zip(words, defs)
import csv
with open("Dictionary_output.txt", 'w') as f:
writer = csv.writer(f, delimiter='\t')
writer.writerows(dat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment