Q:

PYTHON INTERSECTION WITH 3 LISTS

I have to find an intersection between 3 lists with the same format(?)
I know how to do it btw two lists, like below:
    l=list(input("input:"))
    m=list(input("input:"))
    def intersect(l, m):
      return list(set(l) & set(m))

But it seems to not work with 3 lists!!!
a = list(input("Input:"))
b = list(input("Input:"))
c = list(input("Input:"))
def intersect(a, b, c):
  return list(set(a) & set(b) & set(c))

print intersect(a, b, c)

For example, if I input
123
213
312
it should return
[1, 3]

A:

set() doesn't care of order so set([1, 2, 3]) and set([2, 1, 3]) are the same set and set([1, 2, 3]) & set([2, 1, 3]) gives {1,2,3}
You have to use zip(a,b) to get pairs and check pairs
a = list("123")
b = list("213")
c = list("312")

def intersect(a, b, c):
    p = [x for x, y in zip(a, b) if x==y]    
    q = [x for x, y in zip(b, c) if x==y]    
    r = [x for x, y in zip(c, a) if x==y]    
    return p + q + r

print(intersect(a, b, c))

Result:
['3', '1']

You can eventually sort it to get ['1', '3']
    return sorted(p + q + r)

