title: Integer square root in python
body: <p>Is there an integer square root somewhere in python, or in standard libraries?  I want it to be exact (i.e. return an integer), and bark if there's no solution.  </p>
  
  <p>At the moment I rolled my own naive one:</p>
  
  <pre><code>def isqrt(n):
      i = int(math.sqrt(n) + 0.5)
      if i**2 == n:
          return i
      raise ValueError('input was not a perfect square')
  </code></pre>
  
  <p>But it's ugly and I don't really trust it for large integers.  I could iterate through the squares and give up if I've exceeded the value, but I assume it would be kinda slow to do something like that.  Also I guess I'd probably be reinventing the wheel, something like this must surely exist in python already...  </p>