I think this is what you are trying to achieve:
x = []
while True:
data = input()
if data.lower() == "done":
break
if data not in x:
x.append(data)
Note the use of while True
and break
to avoid having two input
calls.
Alternatively, use a set
:
x = set()
while True:
data = input()
if data.lower() == "done":
break
x.add(data)
x = list(x)
This will quietly ignore attempts to add duplicates.
If you actually do want to allow the user to remove items from x
by entering them a second time, you can add the else
and use remove
(for the list) or discard
(for the set), e.g.:
x = set() # or []
while True:
data = input()
if data.lower() == "done":
break
if data in x:
x.discard(data) # or .remove(data)
else:
x.add(data) # or .append(data)
solved How to remove duplicate from string/mixed list