Python笔试题:比较数组a和b 并返回相同和不同元素个数【杭州多测师】【杭州多测师_王sir】
![](https://img2022.cnblogs.com/blog/1257390/202206/1257390-20220614120552104-1457207281.png)
list1 = [1, 3, 4] list2 = [3,4] a = [x for x in list1 if x in list2] #两个列表表都存在 b = [y for y in (list1 + list2) if y not in a] #两个列表中的不同元素 print('a的值为:',a,'相同元素的个数 {}'.format(len(a))) print('b的值为:',b,'不同元素的个数 {}'.format(len(b)))