How to remove duplicate items from a list using list comprehension? I have following code:
a = [1, 2, 3, 3, 5, 9, 6, 2, 8, 5, 2, 3, 5, 7, 3, 5, 8]
b = []
b = [item for item in a if item not in b]
but it doesn’t work, just produces identical list. Why its producing an identical list?
It’s producing an identical list as
bcontains no elements at run-time.What you’d want it this: