How can I compare two lists in python and return not matches

前端 未结 5 2073
夕颜
夕颜 2021-02-05 20:16

I would like to return values from both lists that not in the other one:

bar = [ 1,2,3,4,5 ]
foo = [ 1,2,3,6 ]

returnNotMatches( a,b )

would r

5条回答
  •  星月不相逢
    2021-02-05 20:54

    Just use a list comprehension:

    def returnNotMatches(a, b):
        return [[x for x in a if x not in b], [x for x in b if x not in a]]
    

提交回复
热议问题