Python Iterations Dict values

admin
By -
0

 









Dict Iterate Key and Value using zip() function

code:

#iterating over dict with both key and values through zip


d = {"a": 100, "b": 2, "c": 3}

 

for key,value in zip(d.keys(),d.values()):

     print(key,value)


#output:

a 100

b 2

c 3


We also can use enumerate with items()  function:


d = {"a": 100, "b": 2, "c": 3}


for key,value in enumerate(d.items()):

    print(key,value)

    

#output

'''

0 ('a', 100)

1 ('b', 2)

2 ('c', 3)

>>> 


'''





Tags:

Post a Comment

0Comments

Please Select Embedded Mode To show the Comment System.*