I'm trying to learn python. Here is the relevant part of the exercise:
For each word, check to see if the word is already in a list. If the word is not in the list, add it to the list.
Here is what I've got.
fhand = open('romeo.txt')
output = []
for line in fhand:
words = line.split()
for word in words:
if word is not output:
output.append(word)
print sorted(output)
Here is what I get.
['Arise', 'But', 'It', 'Juliet', 'Who', 'already', 'and', 'and', 'and',
'breaks', 'east', 'envious', 'fair', 'grief', 'is', 'is', 'is',
'kill', 'light', 'moon', 'pale', 'sick', 'soft', 'sun', 'sun',
'the', 'the', 'the', 'through', 'what', 'window', 'with', 'yonder']
Note duplication (and, is, sun, etc).
How do I get only unique values?