a[] = [ 1 2 1 4 5 2 15 1 3 4 ] for a in a[] found = 0 for b in b[] if a = b found = 1 break 1 . . if found = 0 b[] &= a . . print b[]