Also you can use list comprehension In [1]: my_lst = [{'code': 'aaa', 'name': 'a name'}, {'code': 'bbb', 'name': 'b name'}]
In [2]: my_code = 'aaa' In [3]: print [d for d in my_lst if d['code'] == my_code] ------> print([d for d in my_lst if d['code'] == my_code]) [{'code': 'aaa', 'name': 'a name'}] In [4]: On Thu, Jul 23, 2009 at 6:04 PM, Alan Gauld<alan.ga...@btinternet.com> wrote: > > "Alan Gauld" <alan.ga...@btinternet.com> wrote > Oops! > Should be: > >> def findDict(value, dictList): >> for dct in dictList: >> if dct.get('code', '') == my_code > > if dct.get('code', '') == value > >> return dct > > >> HTH, >> >> >> -- >> Alan Gauld >> Author of the Learn to Program web site >> http://www.alan-g.me.uk/ > > _______________________________________________ > Tutor maillist - tu...@python.org > http://mail.python.org/mailman/listinfo/tutor > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor