In [1]:
from euler import make_square_roots

In [2]:
make_square_roots(10)


Out[2]:
[(0, 0),
 (1, 1),
 (4, 2),
 (9, 3),
 (16, 4),
 (25, 5),
 (36, 6),
 (49, 7),
 (64, 8),
 (81, 9)]

In [3]:
def foo(n):
    square_roots = dict(make_square_roots(n))

    for a in xrange(1, n / 2):
        for b in xrange(a + 1, n / 2):
            c_squared = a*a + b*b
            try:
                c = square_roots[c_squared]
            except KeyError:
                continue
            if a + b + c == n:
                yield a, b, c

In [4]:
%timeit list(foo(1000))
list(foo(1000))


1 loops, best of 3: 207 ms per loop
Out[4]:
[(200, 375, 425)]