Finding intersection/difference between python lists

后端 未结 7 1615
别那么骄傲
别那么骄傲 2021-01-12 00:05

I have two python lists:

a = [(\'when\', 3), (\'why\', 4), (\'throw\', 9), (\'send\', 15), (\'you\', 1)]

b = [\'the\', \'when\', \'send\', \'we\', \'us\']
<         


        
7条回答
  •  长发绾君心
    2021-01-12 00:27

    A list comprehension should work:

    c = [item for item in a if item[0] not in b]
    

    Or with a dictionary comprehension:

    d = dict(a)
    c = {key: value for key in d.iteritems() if key not in b}
    

提交回复
热议问题