Project Euler Problem 37 in Python
Use the right data structure for the job. If you have

            if int(n) not in primes:


called more than a small constant number of times then primes should not be a list. If you change


primes = [i for i in gen_primes(10000000)]



to

primes = set(i for i in gen_primes(10000000))


you will see a significant speedup.



The algorithm could also be improved. I don't want to go into too much detail here because that's not in keeping with the ethos of Project Euler, but I think I can give you a couple of hints:

The problem statement says that there are only eleven primes matching the criterion. What property of primes with the criterion allowed them to prove that? How can you apply that property to generate them faster?


   If you have found all of the truncatable primes of length n, do you need to loop over all truncations of a candidate number of length n+1?