You're talking about something different. The parent comment is about mutable default arguments are shared between all calls to that function [1], but you seem to be talking about functions defined in for loops all sharing a reference to the same variable [2].
[1] https://github.com/satwikkansal/wtfpython#-beware-of-default...
[2] https://github.com/satwikkansal/wtfpython#-loop-variables-le...
> In this example it's just a constant but this trick is often used with mutable defaults.
Your example doesn't work with mutable defaults. Ironically it falls into the trap the parent comment was referring to!
def main():
funcs = []
arg = []
for x in range(10)
arg.append(x)
def f(arg=arg):
return arg
funcs.append(f)
print(*[f() for f in funcs], sep="\n")
# result: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] printed 10 times
These functions will all return the same 10-element list. Instead you need to use `def f(arg=arg[:])` or `def f(arg=copy(arg))` (after from copy import copy).
> print([f(x) for f in funcs])
Just a typo but you meant print([f() for f in funcs])