This is a very simple problem but I have no idea why python is doing this. For the loop below, the if head != None...
is creating a local variable such that the head += 1
is not modifying the head in for head in myHeap.array
. adding a print(head) right after the head += 1 is producing the result I want, but the head outside the if statement remains the same.
for head in myHeap.array:
if head != None and count % int(grow) == 0:
head += 1
so the input myHeap.array = [2, 2, 2, 1] outputs the same list at the end of the iteration, when [3, 3, 3, 2] is expected. I have also verified that the condition is met for the if statement and the interpreter uses the head += 1
line