0
c_k_list = [[0, 0]]*(sorted_degrees[len(sorted_degrees)-1]+1)

c_k_list[entry[1]][0] = c_k_list[entry[1]][0]+1

where entry[1]=1

In the above statement, instead of adding 1 to a particular element in c_k_list, it adds 1 to all the rows. Eg: c_k_list is

[[1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0], [1, 0]]

instead of

[[0,0], [1,0], [0,0]......[0,0]]
Blckknght
  • 100,903
  • 11
  • 120
  • 169
shs
  • 66
  • 1
  • 3

1 Answers1

1

Lists are objects, and so are stored by reference. Using * will just create copies of that reference. To correct this try:

c_k_list = [[0, 0] for i in range(5)] 
c_k_list[1][0] = c_k_list[1][0]+1
armatita
  • 12,825
  • 8
  • 48
  • 49