def intersect(seq,seq1):
res = []
for x in seq:
if x in seq1:
res.append(x)
return res
return res only retu
Your return res
indentation is wrong. It should be:
def intersect(seq,seq1):
res=[]
for x in seq:
if x in seq1:
res.append(x)
return res
>>> intersect('scam','spam')
['s','a','m']
What you were doing earlier was that you were appending one value and then returning it. You want to return res
when you have appended all
your values. This happens after the for
loop and that is when you put the return res
line. Therefore, it should have the same indentation as the for
statement.