How do you do arrays
Kartic
kartic.krishnamurthy at gmail.com
Tue Feb 1 16:21:19 EST 2005
Tom - I answered your question even before you posted it!
You have to use iMatrix.append(k) and NOT iMatrix[index] = k.
Also, what do you expect out of:
while index < majorlop1:
print '- %s %s' % ( iMatrix[index], sep)
This loop will never get executed because your previous loop finishes
due to the same condition index < majorlop1.
I am not sure what book you are using but I don't think it is a very
good one.
> I would like to set the size of the List/array independent
> of having to intialialize it prior to use.
You can do the following when you allocate your list.
iMatrix = [''] * size # where size is an integer
and this will give you a list of size empty elements. If you do this,
do not use iMatrix.append(). Use the array notation like you have in
you code currently.
Thanks
-Kartic
More information about the Python-list
mailing list