how to find position of dictionary values
lee
san82moon at gmail.com
Mon Sep 1 04:44:32 EDT 2008
On Sep 1, 1:21 pm, Alexandru Palade
<alexandru.pal... at sellerengine.com> wrote:
> lookfor = 'dfsdf'
> for item, value in kev.items():
> if lookfor in value:
> print item
> print value.index(lookfor)
> break # assuming you only want one result
>
> You can also skip the 'if' verification in which case you need to catch
> ValueError exception in case there is no such entry in the current list.
>
> Hope it helps.
>
> lee wrote:
> > hi,
> > i have a dictionary as follows :
> > kev : {'phno': ['dgsd', 'gsdg', 'dfsdf', 'g'], 'email': ['dg',
> > 'sgsd', 'sdfsdf', 'gdf'], 'name': ['ds', 'dsg', 'dsfds', 'fgdf'],
> > 'address': ['sdg', 'dsgsdg', 'sdf', 'dfg']}
>
> > if user is enters the 3rd item of key phno, ie "dfsdf" in my dict,
> > how can i find it is the third item in the internal list of phno of
> > that dictionary? thanks you.
> > --
> >http://mail.python.org/mailman/listinfo/python-list
hi, thank u your solution is exactly wat i wanted :)
More information about the Python-list
mailing list