0
What I just want to achieve is to be able to get a list with elemnts that aren't repeating
<current state>
results = ["Anna","Michael","Anna","Juliet","Juliet", "Anna"]

<expectation>
results=["Anna","Michael", "Juliet"]

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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"]))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.