I wrote a helper to collect ADC samples: def add_sample(value, samples=[]): samples.append(value); return samples. I expected every call without the second argument to start with a fresh empty list. Instead add_sample(1) returns [1], and the next call, add_sample(2), returns [1, 2].
Why is the list remembered between calls when it is only a parameter, and what is the recommended way to write a default that is an empty list or dictionary?




