Multiple values for one key

Tim Rowe digitig at gmail.com
Thu Aug 28 12:45:02 EDT 2008


2008/8/28 Bruno Desthuilliers <bruno.42.desthuilliers at websiteburo.invalid>:

> You can either use 1/ a list of dicts, or 2/ a dict mapping keys to lists.
>
> 1/
> records = [
>   {"name":"guy", "address":"unknown","zip":"00000"},
>   {"name":"girl", "address":"123 tiny street","zip":"12345"},
>   {"name":"boy", "address":"321 here","zip":"33333"},
>   {"name":"gal", "address":"999 over there","zip":"55555"},
> ]

I think I'd make a class with members name, address, zip, etc. Then
make a list of instances of that class or (better for access) identify
a primary key -- what *is* unique about each entry -- and use that as
a dictionary key with class instances as values. Or use a DBMS.
Certainly the original poster should read up on database design, or
chances are he'll have a nightmare maintaining referential integrity.

-- 
Tim Rowe



More information about the Python-list mailing list