How to remove duplicate items from a list using list comprehension?

前端 未结 7 1047
庸人自扰
庸人自扰 2020-11-30 11:43

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 =         


        
相关标签:
7条回答
  • 2020-11-30 12:27

    The reason that the list is unchanged is that b starts out empty. This means that if item not in b is always True. Only after the list has been generated is this new non-empty list assigned to the variable b.

    0 讨论(0)
提交回复
热议问题