use itertools.product
to get the tuples (you will have to filter out the same number twice), then use set
intersections of the digits to see if they have any digits in common.
import itertools
numbers = [12, 23, 26, 54]
[t for t in itertools.product(numbers, numbers) if set(str(t[0])) & set(str(t[1])) and t[0] != t[1]]
[(12, 23), (12, 26), (23, 12), (23, 26), (26, 12), (26, 23)]
without itertools
you can just build the tuples yourself.
numbers = [12, 23, 26, 54]
[(i, j) for i in numbers for j in numbers if set(str(i)) & set(str(j)) and i != j]
[(12, 23), (12, 26), (23, 12), (23, 26), (26, 12), (26, 23)]
2
solved How to know if a number is in another number python