Reputation: 393
i have been working on this for quite a time and my if statement does not seem to have any effect on the code. what I am trying to do is that I want to enter words in a list without repetition.
fname = raw_input("Enter file name: ")
fh = open(fname)
lst = list()
for line in fh:
line.rstrip()
words = line.split()
if lst.count(words) == 0:
lst = lst + words
lst.sort()
print lst
Upvotes: 2
Views: 752
Reputation: 116
>>> instuff = """one two three
... two three four
... three four five
... """
>>> lst = set()
>>> for line in instuff.split("\n"):
... lst |= set(line.split())
...
>>> lst
set(['four', 'five', 'two', 'three', 'one'])
>>>
Upvotes: 2