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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -