ibramoh ibramoh - 8 months ago 53
Python Question

Avoid duplicate items Python

Hi i am having an issue with duplicate items in a list in python
for example I have this list

i = ['hello', 'hi', 'bye' 'welcome', 'hi', 'bye']

I want to print every item once, even if it's duplicated print it once.

Is there any way to do it in python ??


If the order doesn't matters, then you can use a set:


Otherwise you can do something like this:

seen = set()
for e in i:
    if e not in seen: