creating really big lists

Paul McGuire ptmcg at austin.rr.com
Thu Sep 6 03:30:49 EDT 2007


On Sep 6, 12:47 am, Dr Mephesto <dnh... at googlemail.com> wrote:
>
> I need some real speed! a database is waaay to slow for the algorithm
> im using. and because the sublists are of varying size, i dont think I
> can use an array...- Hide quoted text -
>
> - Show quoted text -

How about a defaultdict approach?

from collections import defaultdict

dataArray = defaultdict(lambda : [[],[],[],[],[]])
dataArray[1001][3].append('x')
dataArray[42000][2].append('y')

for k in sorted(dataArray.keys()):
    print "%6d : %s" % (k,dataArray[k])

prints:
  1001 : [[], [], [], ['x'], []]
 42000 : [[], [], ['y'], [], []]

-- Paul





More information about the Python-list mailing list