I am currently running some python code to extract words from a list and create a list of these words.
The list I am using is from a .txt file with some lines from romeo and juliet.
I read in the file, trimmed the whitespace, split each word up, and added these words to a list.
I am now trying to create a list that does not include any words repeating.
I know that I need to create a loop of some sort to go through the list, add the words, and then discard the repeated words.
This is the code I currently have:
fname = input ("Enter file name: ")
#Here we check to see if the file is in the correct format
#If it is not, we will return a personalized error message
#and quit the programme.
try :
fh = open(fname)
except :
print("Enter a valid file name: ")
quit()
#Here I read in the file so that it returns as a complete
#string.
fread = fh.read()
#print(fread)
#Here we are stripping the file of any unnecessary
#whitespace
fstrip = fread.rstrip()
#print(fstrip)
#Here we are splitting all the words into individual values
#in a list. This will allow us to write a loop to check
#for repeating words.
fsplit = fstrip.split()
lst = list(fsplit)
#print(lst)
#This is going to be our for loop.
wdlst = list()
Any help would be greatly appreciated, I am new to python and I just cannot seem to figure out what combination of statements needs to be added to create this new list.
Many thanks,