I am working on a program right now that has the goal of analyzing twin primes in a certain way(twin primes are primes in the form of(p,p+2)). Right now I have a code that counts the twin primes remainders in % 10 form.
This is that code:
def twin_prime_counter_type10(n):
not_prime = []
prime = []
A = range(n + 1)
B = range(n + 1)
for i in xrange(2, n+1):
if i not in not_prime:
prime.append(i)
for j in xrange(i*i, n+1, i):
not_prime.append(j)
for n,i in enumerate(prime):
if not A[n] == prime[n]:
A[i] = 1
count1_3 = 0
count7_9 = 0
count9_1 = 0
for i in B:
if B[i] % 10 == 3 and B[i - 2] % 10 == 1:
if A[i] * A[i-2] == 1:
count1_3 += 1
elif B[i] % 10 == 9 and B[i - 2] % 10 == 7:
if A[i] * A[i-2] == 1:
count7_9 += 1
elif B[i] % 10 == 1 and B[i - 2] % 10 == 9:
if A[i] * A[i-2] == 1:
count9_1 += 1
print count1_3
print count7_9
print count9_1
print sieve(10000)
This part of the code works fine but I was wondering if anyone knows of a way that when I am finding the pairs of (1)'s(the twin primes) I could also record the order they appear in the list. I don't need anyone to actually write the code that does this, I am just asking if anyone knows of a built in tool in python that I could use to preform this task.
Thanks for the help.