a = [10, 12, 34, 542, 63653, 635, 635] b = [21, 5165, 623, 542, 10] print(sorted(set(a).intersection(b)))