from math import sqrt def is_prime(x): """ Check if `x` is prime. """ return all(x % i != 0 for i in range(2, int(sqrt(x)) + 2)) def next_prime(x): """ Find the next prime number that is strictly bigger than `x`. """ for i in range(x+1, 2 * x): if is_prime(i): return i