Arrays: Difference between revisions
m
→{{header|Python}}: small fix
Alextretyak (talk | contribs) (Added 11l) |
Alextretyak (talk | contribs) m (→{{header|Python}}: small fix) |
||
Line 5,839:
However this will not work as intended if one tries to generalize from the syntax:
<lang python>myArray = [[0]* width] * height
This creates a list of "height" number of references to one list object ... which is a list of width instances of the number zero. Due to the differing semantics of immutables (strings, numbers) and mutables (dictionaries, lists), a change to any one of the "rows" will affect the values in all of them. Thus we need to ensure that we initialize each row with a newly generated list.
|