python - How can i remove overlap in list? -
i made example python list.
list_1 = [1,3,2,2,3,4,5,1] print(list_1)
[1, 3, 2, 2, 3, 4, 5, 1]
to remove overlap, tried use set().
print(set(list_1))
{1, 2, 3, 4, 5}
but want make
[1,3,2,4,5]
i want remove overlap in list, want order not changed.
how can that?
you can use list-comprehension filter (initialize empty list first, ignore resulting list)
list_u = [] [list_u.append(v) v in list_1 if v not in list_u]
Comments
Post a Comment