Reputation: 25
<current state>
results = ["Anna","Michael","Anna","Juliet","Juliet", "Anna"]
<expectation>
results=["Anna","Michael", "Juliet"]
Upvotes: 0
Views: 71
Reputation: 2123
You can conver the list to a set, which has no duplicates by definition.
results = set(["Anna","Michael","Anna","Juliet","Juliet", "Anna"])
If you need the type of the result to be a list, you can simply convert it back:
results = list(set(["Anna","Michael","Anna","Juliet","Juliet", "Anna"]))
Upvotes: 0
Reputation: 36
The following will remove duplicates.
results = ["Anna","Michael","Anna","Juliet","Juliet", "Anna"]
results = list(dict.fromkeys(results))
print(results)
Output:
['Anna', 'Michael', 'Juliet']
See https://www.w3schools.com/python/python_howto_remove_duplicates.asp for more information.
Upvotes: 1