Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python Problem my python version is 3.4.3 please eliminate the punctuations plea

ID: 3681499 • Letter: P

Question

Python Problem

my python version is 3.4.3

please eliminate the punctuations please..

You would like to produce a unique scary dictionary but have a hard time finding the thousands of words that should go into such a dictionary. Your brilliant idea is to write a function scaryDict() that reads in an electronic version of a scary book, say Frankenstein by Mary Wollstonecraft Shelley, picks up all the words in it, and writes them in alphabetical Chapter 6 Problems 209 order in a new file called dictionary.txt. You can eliminate one- and two-letter words because none of them are scary.

You will notice that punctuation in the text makes this exercise a bit more complicated. You can handle it be replacing punctuation with blanks or empty strings. You need textfile caleld franekenstein.txt and create the textfile. And here is the outcome.

>>> scaryDict('frankenstein.txt')

abandon

abandoned

abbey

abhor

abhorred

abhorrence

abhorrent

Explanation / Answer

import string
def scaryDict(filename):
inFile = open(filename)
outFile = open('dictonary.txt', 'w')
content = inFile.read()
content = ''.join([c for c in content.lower() if c in (string.letters + string.whitespace) ])
words = sorted(set(content.split()))
for word in words:
if len(word) <= 2:
words.remove(word)
print(words[:40])
scaryDict('frankenstein.txt')