Python笔试题:比较数组a和b 并返回相同和不同元素个数【杭州多测师】【杭州多测师_王sir】

 

 

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)))

 

posted @ 2022-06-14 12:07  多测师_王sir  阅读(60)  评论(0编辑  收藏  举报