a = [1,2,3,4,5] b = [1,3,5,6] c = a and b print c
actual output: [1,3,5,6] expected output: [1,3,5]
[1,3,5,6]
[1,3,5]
How can we ac
This way you get the intersection of two lists and also get the common duplicates.
>>> from collections import Counter >>> a = Counter([1,2,3,4,5]) >>> b = Counter([1,3,5,6]) >>> a &= b >>> list(a.elements()) [1, 3, 5]