from itertools import combinations
def GetPythagoreanTriples(lst):
dic = dict((val ** 2, val) for val in lst)
print(dic)
return [(dic[x], dic[y], dic[x+y]) for x,y in combinations(dic, 2) if x+y in dic.keys()]
lst = [2, 3, 4, 5, 6, 7, 8, 9, 10]
print(GetPythagoreanTriples(lst))
'''
run:
{4: 2, 9: 3, 16: 4, 25: 5, 36: 6, 49: 7, 64: 8, 81: 9, 100: 10}
[(3, 4, 5), (6, 8, 10)]
'''