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!