3 ms·
Instead of for a in range(1,27) for b in range(1,27) if a == 2*b ... you could try for b in range(1,27) for a in [2*b] if a < 27 ...
by ant6n 10y ago
Instead of
for a in range(1,27) for b in range(1,27) if a == 2*b ...
you could try
for b in range(1,27) for a in [2*b] if a < 27 ...
- sirclueless 10y agoThis is true for the toy example. In the actual problem, the loop guards are quadratic equations or even higher order, and his first method generalizes better (and for small ranges is hardly slower).