3 ms·
Lists in Python are always references. There’s a separate type called tuple specifically designed to represent lists-as-values. If you do [()]*4 then you get
by zarzavat 3y ago
Lists in Python are always references.
There’s a separate type called tuple specifically designed to represent lists-as-values.
If you do [()]*4 then you get exactly what you want.
- dragonwriter 3y ago> There’s a separate type called tuple specifically designed to represent lists-as-values. tuples are also references, but to an immutable object. > If you do [()]*4 then you get exactly what you want. I think what is actually wanted here is four different mutable lists rather than the same mutable list four times, something like what you would get from: [[] for _ in range(4)]