while 1: a,b=input().split() f=1 for i in range(len(a)-1): for j in range(i+1,len(a)): if a[i]==a[j] and b[i]!=b[j]:f=0 if b[i]==b[j] and a[i]!=a[j]:f=0 if f: print(a,b)

Note that non-ascii characters in the above source code will be escaped (such as \x9f).