insertion in lists

Greg Ewing (using wmwd2zz02 at
Thu Mar 4 04:52:29 CET 2004

Lupe wrote:
> I'm trying to have a kind of multi-dimensional list which seems to me to be
> the best way to have an array of not known extension, at the begining of
> the program.

You might also like to consider using a dictionary indexed
by a tuple, which behaves like a sparse array, so you can
do things like

   d = {}
   d[0, 0] = 'a'
   d[5, 7] = 'b'

without having to worry about pre-allocating lists and
sub-lists of the right lengths first.

Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand

More information about the Python-list mailing list