3
I have a text file with many repeated words. I need every word in the file to appear only once.
import codecs
wordList = codecs.open('Arquivo.txt' , 'r')
wordList2 = codecs.open('Arquivo2.txt', 'w')
for x in range(len(wordList)) :
for y in range(x + 1, len(wordList ) ):
if wordList[x] == wordList[y]:
wordList2.append(wordList[x] )
for y in wordList2:
wordList.remove(y)
Error presented
for x in range(len(wordList)):
TypeError: object of type 'file' has no len()
What specific difficulty are you encountering?
– Isac
The iteration part between the words I’m having trouble solving.
– Rivaldo Hater
Take a look at my answer, to do
len(wordList)
it is necessary thatwordList
be a list, and the way you did it is still a_io.TextIOWrapper
– Sidon