2009-06-18 18 views
-1

どのように私はPythonで辞書を横断するのですか?辞書?

+0

あなたはすでにこれを聞いていませんでした?:http://stackoverflow.com/questions/1006575/how-do-i-traverse-a-dictionary-in-python-closed – gnovice

+0

また、この質問を複製します:http://stackoverflow.com/questions/380734/how-to-do-this-python-dictionary-traverse-and-search – mezoid

答えて

0

質問を正しく解釈している場合は、さまざまな方法で辞書を横断できます。

初心者の方には、hereとお読みください。

また、辞書はあなたのベスト・ベットではないかもしれません。もっと情報があれば助けになるでしょう。

1

多くの方法!少数だが、それはより複雑なものにこれらの簡単な方法から逸脱し始め

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]) 

。すべてのコードがテストされました。