a=line1.split(',') b=line2.split(',') m='' for i in a: for n in b: if i==n: m +=i else: return '' return m