Sorry for the confusion, Simon, this is almost exactly what I need, but i need to be able to search for a string in a given value of an item
Here is an example of the dict I am working with {'252': [{'code': '51679', 'date': '2009-08-01 11:35:38', 'userfield': '252', 'from': '9876662881', 'to': '19877760406', 'fpld': '"Foobar" <9855562881>', 'result': 'ANSW', 'sec': 131}, {'code': '51679', 'date': '2009-08-01 14:33:55', 'userfield': '252', 'from': '9876662881', 'to': '19877770391', 'fpld': '"Foobar" <9876555881>', 'result': 'ANSW', 'sec': 86}]} 252 being the key, I need to be able to search for a string in a given item , say 777 in the 'to' field so print wtf(dict,'to','777') would return {'252': [{'code': '51679', 'date': '2009-08-01 11:35:38', 'userfield': '252', 'from': '9876662881', 'to': '19877760406', 'fpld': '"Foobar" <9855562881>', 'result': 'ANSW', 'billsec': 131}, {'code': '51679', 'date': '2009-08-01 14:33:55', 'userfield': '252', 'from': '9876662881', 'to': '19877770391', 'fpld': '"Foobar" <9876555881>', 'result': 'ANSW', 'billsec': 86}]} I hope this makes sense, sorry for not being clear On Sep 23, 2:57 pm, mike171562 <support.desk....@gmail.com> wrote: > i am trying to search a large Python dictionary for a matching value. > The results would need to be structured into a new dictionary with the > same structure. Thanks. > > The structure is like this > > { Key : [{'item':value,'item2':value,' > item3':value,'item4':value,'item5':value','item6':value,'item7':value,'item > 8':value,'item9':value}], > Key2 : > [{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','it > em6':value,'item7':value,'item8':value,'item9':value}], > Key3 : > [{'item':value,'item2':value,'item3':value,'item4':value,'item5':value','it > em6':value,'item7':value,'item8':value,'item9':value}] > > } > > On Sep 22, 7:16 pm, Dave Angel <da...@ieee.org> wrote: > > > > > Support Desk 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}] > > > > What would be the best way to search for a specific value of item1 and add > > > all the results to a new dictionary? Thanks > > > With all the messages I've seen so far on this thread, all you've > > managed to do is confuse it further. I suggest you start over (new > > thread) with a legal program defining a single dictionary (with real > > values for Key, Key2, and value, and without extra quote marks which > > make it fail to compile even if we guess what you're doing with the > > three keys). I suggest that at least some relevant parts of the data > > should not be all identical, so we can tell what's important. > > > Use copy & paste from working code. > > > Then given a real dictionary, describe what you really want to search > > for, and what acceptable results would be. > > > And also specify the programming language, version, and OS environment. > > > Thanks. > > DaveA -- http://mail.python.org/mailman/listinfo/python-list