How to print key of a dictionary using an iterator?

How to print the key of a dictionary in python using an iterator?

1 Like

for key, value in dict.items():
print(key,value)

1 Like

If you truly only need the keys, you can do

for key in dict:
    print(key)

If (as is more common) you need to use both keys and values within the for block, you can do

for key,value in dict.items():
    print(key, value)
2 Likes