I was trying to write a program that calculates prime number, an effective program.
i was trying some different ways to attack the issue.
def is_prime2(self, cand):
for number in range(2, int(round(self.get_sqrt(cand)))):
if cand % number == 0:
return False
return True
def is_prime(self, cand):
return all(cand % number != 0 for number in range(2, int(round(self.get_sqrt(cand)))))
the is_prime2 method is much more faster than the is_prime method.
I'm trying to understand the reason for this difference, any ideas?
Also, is there a way to optimize the is_prime method?