How to use a Python dictionary?

前端 未结 7 1058
闹比i
闹比i 2020-12-11 21:24

I am finding it difficult to iterate through a dictionary in python.

I have already finished learning via CodeAcademy and solo learn but still find it tough to go th

7条回答
  •  误落风尘
    2020-12-11 21:58

    Dictionaries are the python equivalent of Hash table. It stores values as key-value pairs. Values can be any python objects whereas, keys need to immutable.

    Below are some of the ways to iterate over a dictionary in python

    # Iterating over the keys.
    for k in dict:
    for k in dict.keys():
    
    #Iterating over the values.
    for v in dict.values():
    
    #Iterating over both the key and values.
    for k,v in dict.items():
    

提交回复
热议问题