> -----Original Message----- > From: Chris Rebert <c...@rebertia.com> > Sent: Tuesday, September 22, 2009 5:35 PM > To: Support Desk <support.desk....@gmail.com> > Cc: python-list@python.org > Subject: Re: Searching a large dictionary >> On Tue, Sep 22, 2009 at 5:22 PM, Chris Rebert <c...@rebertia.com> wrote: >>> On Tue, Sep 22, 2009 at 2:50 PM, Support Desk >>> <support.desk....@gmail.com> wrote: >>> > I need help searching a large python dictionary. The dictionary is setup >>> > like so >>> > >>> > >>> > Key[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}] >>> > >>> > >>> > Key2[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}] >>> > >>> > >>> > Key3[{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}] >>> >>> That is not valid syntax. Do you mean you have a dictionary like this?: >>> >>> { Key : >>> [{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}], >>> Key2 : >>> [{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}], >>> Key3 : >>> [{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item8':value,'item9':value}] >>> } > On Tue, Sep 22, 2009 at 3:30 PM, Support Desk > <support.desk....@gmail.com> wrote: >> Chris, Yes that is the correct syntax, thanks > > Ok, so what would the new dictionary you want look like exactly? A > list would seem the natural datatype for the results, but you want a > dict. On Tue, Sep 22, 2009 at 3:41 PM, Support <support.desk....@gmail.com> wrote: > Chris, a list would work fine, the results are being rendered to a django > template
results = [] for lst in your_dict.values(): d = lst[0] try: results.append(d[item1]) except KeyError: pass #use results Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list