Answers for "how to call keys in dictionary python in a print statement in a for loop"

4

loop throughthe key and the values of a dict in python

a_dict = {"color": "blue", "fruit": "apple", "pet": "dog"}

# Will loop through the dict's elements (key, value) WITHOUT ORDER
for key, value in a_dict.items():
  print(key, '->', value)
Posted by: Guest on August-31-2020
1

Dictionary Loop thru a dictionary's keys.

dd = {'john':3, 'mary':4, 'joe':5, 'vicky':7}

for kk in dd:
    print(kk)

# john
# mary
# joe
# vicky
Posted by: Guest on December-10-2021

Code answers related to "how to call keys in dictionary python in a print statement in a for loop"

Python Answers by Framework

Browse Popular Code Answers by Language