I'm facing trouble calculating the time complexity of this line. It seems Quadratic O(n**2) to me. Because I have to go through nested loop here if I don't use list comprehension.
AB = Counter([(a+b) for a in A for b in B])
Your line:
AB = Counter([(a+b) for a in A for b in B])
is equivalent to (ignoring the fact that the list comprehension is faster and does not append one by one*):
# given lists A, B
AB0 = []
# this is O(n2)
for a in A:
for b in B:
AB0.append(a+b)
AB = {}
# this is O(m), m=n2
for ab in AB0:
if ab not in AB:
AB[ab] = 0
AB[ab] += 1
So all in all, it is bounded by O(n2).