[Tutor] Accessing Specific Dictionary items

bob gailer bgailer at gmail.com
Tue Aug 2 03:36:24 CEST 2011


On 8/1/2011 8:34 PM, Mike Nickey wrote:

[snip]
>
> [{'city': 'Buena Park', 'region_name': 'CA', 'area_code': 714},
> {'city': 'Wallingford', 'region_name': 'CT', 'area_code': 203},
> {'city': 'Schenectady', 'region_name': 'NY', 'area_code': 518},
> {'city': 'Athens', 'region_name': '35'}]

IMHO this is overkill.

Consider instead using City-Region as the key and storing the pther 
attributes in a tuple. There is no need to have separate dictionaries or 
lots of repetitive keys:

cities = {
'Buena Park CA': (414, 'Santa Clara, CA'),
'Wallingford'CT: (203),...}


-- 
Bob Gailer
919-636-4239
Chapel Hill NC



More information about the Tutor mailing list