# 2 lines in Python

• ``````from collections import Counter

class Solution(object):
def intersect(self, nums1, nums2):
c1, c2 = Counter(nums1), Counter(nums2)
return sum([[num] * min(c1[num], c2[num]) for num in c1 & c2], [])``````

• it looks really weird, hard to understand

• It is great and simple. But what does the empty list mean in sum() ?

• @Helly0000 it's Python's syntax to create a sum of lists.

• @agave Thanks!

• I approached this pretty much in the same way except for the last line:

``````from collections import Counter

class Solution(object):
def intersect(self, nums1, nums2):
c1, c2 = Counter(nums1), Counter(nums2)
return [i for i in c1.keys() for j in range(min([c1[i], c2[i]]))]
``````

• dunno if it is cheating...

• @facss what do you mean?

• @agave yes,we all use the `Counter` but I use `&` to get the intersection.

``````class Solution(object):
def intersect(self, nums1, nums2):
return  list((collections.Counter(nums1)&collections.Counter(nums2)).elements())
``````

• @facss I dont think it's cheating as long as you know how to implement a counter using the base dict in Python

• It would be more concise.

``````class Solution(object):
def intersect(self, nums1, nums2):
"""
:type nums1: List[int]
:type nums2: List[int]
:rtype: List[int]
"""
from collections import Counter
c1 = Counter(nums1)
c2 = Counter(nums2)
return list((c1&c2).elements())
``````

• @haggard this is much better

• I also get one simple solution

``````class Solution(object):
def intersect(self, nums1, nums2):
"""
:type nums1: List[int]
:type nums2: List[int]
:rtype: List[int]
"""
return sum([[i]*min(nums1.count(i),nums2.count(i)) for i in set(nums1)&set(nums2)],[])
``````

• i think it waste so much time

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.