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]:
dict(make_square_roots(10))


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

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

    for a in xrange(1, n / 2 + 1):
        for b in xrange(a + 1, n / 2 + 1):
            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 [5]:
%timeit list(foo(1000))
list(foo(1000))


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