How do you find the first key in a dictionary?

前端 未结 12 917
清酒与你
清酒与你 2020-11-27 10:58

I am trying to get my program to print out \"banana\" from the dictionary. What would be the simplest way to do this?

This is my dictionary:

         


        
12条回答
  •  天涯浪人
    2020-11-27 11:40

    Use a for loop that ranges through all keys in prices:

    for key, value in prices.items():
         print key
         print "price: %s" %value
    

    Make sure that you change prices.items() to prices.iteritems() if you're using Python 2.x

提交回复
热议问题