Press "Enter" to skip to content

How to Remove Duplicate Items from a List in Python?

Here is a Python program to remove duplicate items from a list and will preserve the order.

Remove Duplicate Items From a List in Python

def dedupe(items):
    dup_item = set()
    for item in items:
        if item not in dup_item:
            yield item

if __name__ == '__main__':
    a = [4, 3, 2, 4, 9, 4, 3, 8]


[4, 3, 2, 4, 9, 4, 3, 8]
[4, 3, 2, 9, 8]

Process finished with exit code 0

See also:

Have you found the answer to your question? If not, you can discuss it with me in the comments section below or join my Q&A community for developers and ask your question. It is FREE.

Vinish Kapoor


Hi, I am a full stack developer and writing about development. I document everything I learn and help thousands of people. is created, written, and maintained by me; it is built on WordPress, and hosted by Bluehost. Connect with me on Facebook, Twitter, GitHub, and get notifications for new posts.

Inline Feedbacks
View all comments