[Chicago] 2 unique keys in a python dict?

Lukasz Szybalski szybalski at gmail.com
Thu Oct 9 18:06:12 CEST 2008


On Thu, Oct 9, 2008 at 10:49 AM,  <skip at pobox.com> wrote:
>
>    Lukasz> Is it possible to have multiple keys in a python dictionary?
>
> Certainly.  Though I don't think that's really what you intended to ask.
>
>    Lukasz> Normally its only 1 key, and I need to have 2 dictionaries and
>    Lukasz> somehow manage the uniqueness.
>    Lukasz> me={}
>    Lukasz> me['First']='Lucas'
>    Lukasz> me['Last']='szybalski'
>
>    Lukasz> I would like to get 2 keys? Is there something similar to dict
>    Lukasz> that would have the property that 2 or more keys are unique?
>    Lukasz> me= ?
>
> I'm unclear what you are asking.  Do you want a list of dictionaries?, e.g.:
>
>    names = [
>        {
>            'First': 'Lucas',
>            'Last': 'Szybalski',
>        },
>        {
>            'First': 'Skip',
>            'Last': 'Montanaro',
>        }
>    ]
>


I have multiple records in a csv file for each userid. I need to
calculate total amount paid and last transaction.

id,paid,transaction
3,$10,20080101
3,$10,20080201


Final Total
me={}
me[3]=($20,20080201)  (dictionary with a list)

now
id,subid, paid,transaction
3,1,$10,20080101
3,2,$10,20080201

I guess what Massimo said will work, but now I need to know which row
is the paid and which is transaction?!!
me[3,1]=(10,20080101)
me[3,2]=(10,20080201)

I guess this could do it
me[3,1]={'paid':10 , 'transaction':20080101}

Thanks,
Lucas


More information about the Chicago mailing list