In [1]:
l = [3, 3, 2, 1, 5, 1, 4, 2, 3]

In [2]:
print(set(l))


{1, 2, 3, 4, 5}

In [3]:
print(list(set(l)))


[1, 2, 3, 4, 5]

In [4]:
print(dict.fromkeys(l))


{3: None, 2: None, 1: None, 5: None, 4: None}

In [5]:
print(list(dict.fromkeys(l)))


[3, 2, 1, 5, 4]

In [6]:
print(sorted(set(l), key=l.index))


[3, 2, 1, 5, 4]

In [7]:
l_2d = [[1, 1], [0, 1], [0, 1], [0, 0], [1, 0], [1, 1], [1, 1]]

In [8]:
# l_2d_unique = list(set(l_2d))
# TypeError: unhashable type: 'list'

In [9]:
# l_2d_unique_order = dict.fromkeys(l_2d)
# TypeError: unhashable type: 'list'

In [10]:
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

In [11]:
print(get_unique_list(l_2d))


[[1, 1], [0, 1], [0, 0], [1, 0]]

In [12]:
print(get_unique_list(l))


[3, 2, 1, 5, 4]

In [13]:
print([x for x in set(l) if l.count(x) > 1])


[1, 2, 3]

In [14]:
print([x for x in dict.fromkeys(l) if l.count(x) > 1])


[3, 2, 1]

In [15]:
print(sorted([x for x in set(l) if l.count(x) > 1], key=l.index))


[3, 2, 1]

In [16]:
print([x for x in l if l.count(x) > 1])


[3, 3, 2, 1, 1, 2, 3]

In [17]:
def get_duplicate_list(seq):
    seen = []
    return [x for x in seq if not seen.append(x) and seen.count(x) == 2]

In [18]:
def get_duplicate_list_order(seq):
    seen = []
    return [x for x in seq if seq.count(x) > 1 and not seen.append(x) and seen.count(x) == 1]

In [19]:
print(get_duplicate_list(l_2d))


[[0, 1], [1, 1]]

In [20]:
print(get_duplicate_list_order(l_2d))


[[1, 1], [0, 1]]

In [21]:
print(get_duplicate_list(l))


[3, 1, 2]

In [22]:
print(get_duplicate_list_order(l))


[3, 2, 1]

In [23]:
print([x for x in l_2d if l_2d.count(x) > 1])


[[1, 1], [0, 1], [0, 1], [1, 1], [1, 1]]