accessing dictonary keys thru values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rhitam30111985
    New Member
    • Aug 2007
    • 112

    accessing dictonary keys thru values

    hi every1
    i am an newbie python programmer.. i need to know how do i access a key when given the value in an associative array ? ie.. eg .. in a telephone directory stored as a dictionary..
    if a enter a telephone number i should get the name corresponding to it.
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Originally posted by rhitam30111985
    hi every1
    i am an newbie python programmer.. i need to know how do i access a key when given the value in an associative array ? ie.. eg .. in a telephone directory stored as a dictionary..
    if a enter a telephone number i should get the name corresponding to it.
    Try this:[code=Python]value = '(800) 222-3333'
    key = dd.keys()[dd.values().ind ex(value)][/code]Lists are ordered objects. I believe the list object dd.values() will be ordered the same as dd.keys().

    Comment

    • rhitam30111985
      New Member
      • Aug 2007
      • 112

      #3
      Originally posted by bvdet
      Try this:[code=Python]value = '(800) 222-3333'
      key = dd.keys()[dd.values().ind ex(value)][/code]Lists are ordered objects. I believe the list object dd.values() will be ordered the same as dd.keys().
      hi bvdet,
      thanks a lot.. code works..

      Comment

      Working...