my code has to take the file and put all the words in a list, and then check if they are not repeated, if necessary delete them until it is only 1. However, only the "the" puts it several times enter code here:
plbrs_totales = list()
fnombre = input("Ingrese nombre de archivo:\n")
try:
llave = open(fnombre)
except:
print("Error")
quit()
for lineas in llave:
lineas_ind= lineas.rstrip()
plbrs = lineas_ind.split()
plbrs_totales = plbrs_totales + plbrs
for rep in plbrs_totales:
repwords = plbrs_totales.count(rep)
if repwords > 1:
plbrs_totales.remove(rep)
plbrs_totales.sort()
print(plbrs_totales)
y este es el archivo.txt:
But soft what light through yonder window breaks\n
It is the east and Juliet is the sun\n
Arise fair sun and kill the envious moon\n
Who is already sick and pale with grief\n
and this is the output, why are 2 "the"?
['Arise', 'But', 'It', 'Juliet', 'Who', 'already', 'and', 'breaks', 'east', 'envious', 'fair', 'grief', 'is', 'kill', 'light', 'moon', 'pale', 'sick', 'soft', 'sun', 'the', 'the', 'through', 'what', 'window', 'with', 'yonder']