Skip to content

Instantly share code, notes, and snippets.

@NotTheEconomist
Last active February 20, 2017 20:31
Show Gist options
  • Save NotTheEconomist/a3d3e3798e652259480cbeaeb94dd6b4 to your computer and use it in GitHub Desktop.
Save NotTheEconomist/a3d3e3798e652259480cbeaeb94dd6b4 to your computer and use it in GitHub Desktop.
d = {}
with open("dictfile.txt") as f:
d.update([map(str.strip, line.split("=")) for line in f])
# alternatively:
# for line in f:
# k, v = line.split('=')
# d[k.strip()] = v.strip()
with open("wordfile.txt") as f:
for line in f:
words = filter(None, [str(d.get(word, '')) for word in line]) # the cast to str is actually unnecessary here
# alternatively:
# words = []
# for word in line:
# words.append(str(d.get(word, '')))
# words = filter(None, words)
print(", ".join(words))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment