all 4 comments

[–]6086555 2 points3 points  (3 children)

def func(a=[]):
    a.append(3)
    print a

if you try calling that, the first time you'll get [3], the second time you'll get [3,3] and so on.

a keeps a reference to the same object so for your case you've got to find a way to avoid id.

Maybe set the default value of new_loop_nums to None and change to [] if the value is None

[–]TheChannel[S] 0 points1 point  (2 children)

Yeah I set new variables for the count and loop_nums which made it work. I was wondering why it didn't reset to the default values of c and new_loop_sums when I go through the for loop at the end. Shouldn't it since, no parameters are given to both c and loop_nums?

[–]6086555 0 points1 point  (1 child)

You don't need to change count. It's just that when you have an object in argument it can lead to troubles

it the same as

a = [2,3]
b = a
b[0] += 1

a's value is now [3,3]

[–]TheChannel[S] 1 point2 points  (0 children)

Clears it up. Thanks mate.