ibramoh ibramoh - 1 year ago 77
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 ??

Answer Source

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:
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download