Checking number is prime in python, why check up to int(sqrt(n)-1)) not int(sqrt(n))
Question: new to Python here. I am trying to understand how this function works to check
prime numbers:

    
    
    from itertools import count, islice
    from math import sqrt
    def is_prime(n):
        if n < 2: return False
        return all(n%i for i in islice(count(2), int(sqrt(n)-1)))
    

From what I understand you can check factors up to and **including** the
square root of n, so why is this only testing up to sqrt(n)-1? I'm also not
clear on the `return all` part for the function. n%i returns an int, the
remainder. So why does this expression evaluate as a bool? Any pointers on
this would be great. thanks!


Answer: Because the second argument to `islice` is a count, not the value to stop on.

This would be far better written with `xrange(2, int(sqrt(n))+1)`

The plus one here is to make the range inclusive at both ends, which xrange
normally is not.

