[Tutor] Strengths & weaknesses of Python lists compared to "old school" arrays [Was "Fixed Vector Array"]
Mark Lawrence
breamoreboy at yahoo.co.uk
Thu Mar 5 21:54:38 CET 2015
On 05/03/2015 10:07, Alan Gauld wrote:
> On 04/03/15 19:10, boB Stepp wrote:
>> wanted to address an item in a 3-dimensional array, I would use
>> something like (x, y, z) whereas the Python list form amounts to
>> [x][y][z] .
>
> That's just a syntax thing, Python could have allowed single
> bracketing of index, Guido chose to follow his mantra of explicit
> is better than implicit. Many array based languages (including C)
> also require multiple explicit indices.
>
You could regard this a code smell in Python. Perhaps the most repeated
thing written here by beginners is something like:-
for i in range(len(this)):
for j in range(len(that)):
for k in range(len(other)):
if mystruct[i][j][k] then:
...
An experienced Pythonista's code would maybe be:-
for x in mystruct:
for y in x:
for z in y:
if z:
...
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
More information about the Tutor
mailing list