Re:Ask HN: What are your favorite examples of elegant software?
by darkfirefly on Monday May 02, 2022 @09:58PM
(#31243529)
Python's default arguments are evaluated and stored once. This can cause issues, for example the naive "default to []" program:
A correct implementation would be:
[ Parent
| on HN ]
Re:Ask HN: What are your favorite examples of elegant software?
by MisterBiggs on Tuesday May 03, 2022 @12:24AM
(#31244596)
Surprised to see this works for list() as well.
>>> def func(b, a=list()):
... a.append(b)
... print(a)
...
>>> func(3)
[3]
>>> func(3)
[3, 3]
Honestly surprised this quirk hasn't bit me yet