views:

167

answers:

3

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

A: 

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.

LogicKills
+1  A: 

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.

DoxaLogos
A: 

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