def scary(filename):
infile = open(filename, 'r')
content = infile.read()
infile.close()
for i in ';",.()[]{}\/0123456789@#!$':
content = content.replace(i, ' ')
words = content.split()
d = {}
for word in words:
if word in d:
continue
else:
d[words] = words
lst = []
for n in d:
lst.append(n)
lst.sort()
outfile = open('dictionary.txt', 'w')
for words in lst:
outfile.write(words + '\n')
outfile.close()
I am suppose to write a function scary() that reads in an electronic version of a scary book (it could be any book), picks up all the words in it and writes them in alphabetic order in a new file called dictionary.txt.