0

Hi

Okay so i have a text file and i have it converted to a bunch of lists with strings as the words. Now i need to find words that occur only once in the entire text file, how can i do this using a loop?
A hint says that i should make 2 lists, one should keep track of words appear once, and the other should have words that appear more than once. Also i can't use sets and dictionaries.

Any clues?

I've tried something like this:

wordsingle = []
worddouble = []
    for word in l:
        if word in l > 2:
            worddouble.append(word)
        else:
            wordsingle.append(word)
    return worddouble

But it doesn't work, im stuck here.

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by cghtkh
2
wordsingle = []
worddouble = []
for word in l:
    if word in wordsingle:
       worddouble.append(word)
    else:
       wordsingle.append(word)
    
return [ word for word in wordsingle if word not in worddouble]

Edited by cghtkh: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.