Q:

Iterating through keys in dictionaries

nums={'1':'one',
'2':'two',
'3':'three',
'4':'four',
'5':'five'}

nums['6']='six'
for i in range(1,7):
    print(nums[str[i]])

Output:
TypeError: 'type' object is not subscriptable

I found out alternative ways of doing that when the keys are of int type, but I am still curious as to why it didn't work.

A:

You need to call the str type:
print(nums[str(i)])

You were trying to index str with str[i] (square brackets).

