The question is to:
- Firstly,find the number of all words in a text file
- Secondly, delete the common words like, a, an , and, to, in, at, but,... (it is allowed to write a list of these words)
- Thirdly, find the number of the remaining words (unique words)
- Make a list of them
the file name should be used as the parameter of the function
I have done the first part of the question
import re
file = open('text.txt', 'r', encoding = 'latin-1')
word_list = file.read().split()
for x in word_list:
print(x)
res = len(word_list)
print ('The number of words in the text:' + str(res))
def uncommonWords (file):
uncommonwords = (list(file))
for i in uncommonwords:
i += 1
print (i)
The code shows till the number of the words and nothing appears after that.