The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 314 Weeks Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
Hey can you modify this code match with the assignment's requirements?
http://www2.cs.uh.edu/~acl/cs1306/Assignment/prog9.pdf
#Step 1
f = open('stopwords.txt', "r")
content = f.readlines()
stopwords = [x.replace('\n','') for x in content]
print("List of Stop words")
print(stopwords)
#Step 3: read from the text file, line by line and clean words
allWords = []
fl = open('news.txt', "r", errors='ignore')
lines = fl.readlines()
print("\n\n")
f2 = open('news.txt', "r", errors='ignore')
print(f2.read())
for line in lines:
     #remove punctuations
     punctuations = ["?",".","!","/",";",":","-","(",")",",","$",'"',".",'\n']
     for punctuation in punctuations:
           if punctuation in line:
                 line = line.replace(punctuation, "")
     #change to lowercase
     line = line.lower()
     words = line.split(' ')
     #add words to a wordlist
     allWords.extend(words)
print('\nWordlist: ')
print(allWords)
allWords.sort()
print('\nWord List Sorted: ')
print(allWords)
#remove stopwords, & numbers
for w in allWords:
     for _ in range(allWords.count(w)):
           allWords.remove(w)
print('\nStop Word Removed ')
print(allWords)Â Â
nonNumeric = []Â Â
for w in allWords:
     if (w.isnumeric()==False):
           nonNumeric.append(w)
print('\nNumbers Removed ')
print(nonNumeric)
#remove duplicates
nonDuplicates = []
for w in nonNumeric:
     if w not in nonDuplicates:
           nonDuplicates.append(w)
print('\nDuplicated words Removed ')Â Â Â Â Â
print(nonDuplicates)
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly