나는 이렇게 학습한다/Algorithm & SQL

0211. Remove duplicates from list

daco2020 2023. 2. 12. 00:12

Define a function that removes duplicates from an array of numbers and returns it as a result.

The order of the sequence has to stay the same.



Solution:

def distinct(seq: list[int]) -> list[int]:
    result = []
    for i in seq:
        if i not in result:
            result.append(i)
    return result
def distinct(seq: list[int]) -> list[int]:
    return sorted(set(seq), key=seq.index)
def distinct(seq: list[int]) -> list[int]:
    return list(dict.fromkeys(seq))