# How can I speed up this project Euler Q#35 solution?

How can I speed up this code? It takes too long if I run it with standard python interpreter. However, I am able to reduce execution time to 13 seconds by running in "pypy" interpreter.

Project Euler problem: https://projecteuler.net/problem=35

The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime. There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97. How many circular primes are there below one million?

``````from collections import deque

def sieve(limit):
nums = (True) * (limit+1)
nums(0) = nums(1) = False

for i, is_prime in enumerate(nums):
if is_prime:
yield i
for n in range(i*i, limit+1, i):
nums(n) = False

def rotations(n):
l = deque(list(str(n)))
r = ()

for _ in range(len(l)):
r.append(int("".join(list(l))))
l.rotate()
return r

def circular_prime(n):
cp = ()
s = list(sieve(n))
for i in s:
r = rotations(i)
flags = (False) * len(r)
for k, j in enumerate(r):
if j in s:
flags(k) = True
if all(flags):
print(i)
cp.append(i)
return len(cp)

print(circular_prime(1000000))
$$```$$
``````