creating really big lists

Dr Mephesto dnhkng at googlemail.com
Fri Sep 7 15:16:46 EDT 2007


On 6 Sep., 09:30, Paul McGuire <pt... at austin.rr.com> wrote:
> 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

hey, that defaultdict thing looks pretty cool...

whats the overhead like for using a dictionary in python?

dave




More information about the Python-list mailing list