I am pretty new to Python and struggle to count my amount of equal sums in my list of lists. I create a list of numbers (list oneven), according to Goldbach every number is equal to three Primenumbers. I now have a list of all combination of prime numbers, now I want to count the amount of combinations that every number in list oneven has, and print it out. I tried using "import Collections" which wouldn't work due to my code not being hashable. Then I tired adding a number to an empty list which rises to the equal sums but I get the error message:
IndexError: list assignment index out of range
Here is my code with which I am struggling:
lijst2 = []
lijst = []
for i in oneven:
for a in priemgetallen:
for b in priemgetallen:
if a >= b:
c = i - a - b
if c in priemgetallen and b >= c:
lijst.append([c,b,a])
for item in lijst:
if sum(item) in lijst2:
lijst2[sum(item)] = lijst2.get(sum(item))+1
else:
lijst2[sum(item)] = 1
for k,v in lijst2.items():
print(str(k)+':'+str(v))
lijst2 = set(lijst)
print(lijst2)
Incase you are interested in what I am trying to do, I am trying to write a counter for Goldbachs theory, so here is my entire Code:
oneven = []
for i in range(7,102,2):
oneven.append(i)
priemgetallen = [2]
counter = 3
while priemgetallen[-1] < oneven[-1]:
priemgetallendelers = []
for i in range (1,counter+1):
if counter % i == 0:
priemgetallendelers.append(i)
if len(priemgetallendelers) == 2:
priemgetallen.append(counter)
counter += 1
else:
counter +=1
lijst2 = []
lijst = []
for i in oneven:
for a in priemgetallen:
for b in priemgetallen:
if a >= b:
c = i - a - b
if c in priemgetallen and b >= c:
lijst.append([c,b,a])
for item in lijst:
if sum(item) in lijst2:
lijst2[sum(item)] = lijst2.get(sum(item))+1
else:
lijst2[sum(item)] = 1
for k,v in lijst2.items():
print(str(k)+':'+str(v))
lijst2 = set(lijst)
print(lijst2)
At the end it should look a bit like this:
7 = 2 + 2 + 3
9 = 2 + 2 + 5
= 3 + 3 + 3
11 = 2 + 2 + 7
= 3 + 3 + 5
13 = 3 + 3 + 7
= 3 + 5 + 5
Options to write: 7, 9, 11, ...:
1, 2, 2, 2, 3, 4, 3, 5, 5, 5, 7, 7, 6, 9, 8,