[Python] How to remove duplicates from a list in Python while preserving order? [duplicate]

Discussão em 'Python' iniciado por Stack, Abril 21, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to remove duplicate items from a list in Python, but I want to preserve the original order of the elements.

    For example, my_list = [1, 3, 2, 3, 1, 5, 2]

    I tried using set() to remove duplicates: list(set(my_list)) But the order is not preserved. Is there a simple and efficient way to do this in Python?

    I want to get: [1, 3, 2, 5]

    Continue reading...

Compartilhe esta Página