-1

in how many way i traverse dictionary in python???

  • Didn't you ask this already?: http://stackoverflow.com/questions/1006575/how-do-i-traverse-a-dictionary-in-python-closed – gnovice Jun 18 '09 at 04:43
  • Also, it duplicates this question: http://stackoverflow.com/questions/380734/how-to-do-this-python-dictionary-traverse-and-search – mezoid Jun 18 '09 at 04:46

3 Answers3

1

Many ways!

testdict = {"bob" : 0, "joe": 20, "kate" : 73, "sue" : 40}

for items in testdict.items():
    print (items)

for key in testdict.keys():
    print (key, testdict[key])

for item in testdict.iteritems():
    print item

for key in testdict.iterkeys():
    print (key, testdict[key])

That's a few, but that begins to departing from these simple ways into something more complex. All code was tested.

Jay Atkinson
  • 3,279
  • 2
  • 27
  • 41
0

If I am interpreting your question correctly, you can transverse Dictionaries in many ways.

A good read for beginners is located here.

Also a Dictionary might not be your best bet.More information would be helpful, not to mention it would aid in assisting you.

sdsd
  • 61
  • 2
  • 11
0

http://docs.python.org/tutorial/datastructures.html#looping-techniques

>>> knights = {'gallahad': 'the pure', 'robin': 'the brave'}
>>> for k, v in knights.iteritems():
...     print k, v
...
gallahad the pure
robin the brave
David Johnstone
  • 24,300
  • 14
  • 68
  • 71