Python filter a list to only leave objects that occur once

前端 未结 9 746
野的像风
野的像风 2020-12-15 13:18

I would like to filter this list,

l = [0,1,1,2,2]

to only leave,

[0].

I\'m struggling to do it in a \'pythoni

9条回答
  •  离开以前
    2020-12-15 14:00

    [x for x in the_list if the_list.count(x)==1]
    

    Though that's still a nested loop behind the scenes.

提交回复
热议问题