insertion in lists

Greg Ewing (using news.cis.dfn.de) wmwd2zz02 at sneakemail.com
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
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list