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

Lists in Python -

android - can not access to progress bar in an other activity -

java - Vaadin 7 Pass Data Between Views -