[Tutor] dictionaries help

vince spicer vinces1979 at gmail.com
Thu Jul 23 18:46:09 CEST 2009


this should work


def find_value(value, lst):
    for obj in lst:
        if value in obj.values():
            return obj

>> find_value("aaa", my_lst)

Vince

On Thu, Jul 23, 2009 at 9:55 AM, <davidwilson at safe-mail.net> wrote:

> hello,
> please excuse me, but i would like to understand how dictionaris work.
>
> for example:
> >>> my_lst = [{'code': 'aaa', 'name': 'a name'}, {'code': 'bbb', 'name': 'b
> name'}]
> >>> my_code = 'aaa'
>
>
> from the above i would like to compare my_code and return the dictionary
> which has code == my_code
>
> dave
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090723/b168fa83/attachment.htm>


More information about the Tutor mailing list