Anonymous user
Create a two-dimensional array at runtime: Difference between revisions
Create a two-dimensional array at runtime (view source)
Revision as of 10:55, 27 February 2009
, 15 years ago→{{header|Python}}
No edit summary |
|||
Line 361:
{{works with|Python| 2.5}}
<lang python>
'''Note:''' Some people may instinctively try to write myarray as [[0] * width] * height, but the * operator creates ''n'' references to [[0] * width]
Line 371:
You can also use a two element tuple to index a dictionary like so:
<lang python>
# or, in Python 3: myarray = {(w,h): 0 for w in range(width) for h in range(height)}
myarray[(0,0)] = 3.5▼
=={{header|Ruby}}==
|