I’d like to share a very simple function definition with you. All it does is tell you if a number is a perfect square (e.g. 4, 9, 16, 25, 36) or not. It uses existing methods. But it’s the fastest method I’ve found so far. I can compute 50,000,000 numbers in under 50 seconds on my Macbook.
from math import sqrt def is_perfect_square(n): return sqrt(n).is_integer()