We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is also prime.
What is the largest n-digit pandigital prime that exists?
It is easy to see that all 8-digit and 9-digit pandigital numbers are divisible by 3.
from itertools import permutations
def p41():
for p in permutations('7654321'):
if p[-1] in {'2','4','5','6','8'}: continue
if isprime(int(''.join(p))): break # isprime function see link below
return ''.join(p)
7652413