Jump to content

Arrays: Difference between revisions

1 byte removed ,  3 years ago
m
(Added 11l)
Line 5,839:
However this will not work as intended if one tries to generalize from the syntax:
 
<lang python>myArray = [[0]* width] * height] # DOES NOT WORK AS INTENDED!!!</lang>
 
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.
1,481

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.