The first problem here is that you are trying to extract string indices from a string itself. That is because when you iterate over den.items() you are iterating over its keys and values as user and user_info respectively.
So for every iteration of the loop -:
user = key
user_info = val
Now if you notice the dictionary you are using has values as strings.
For e.g. if you have a string say 'hi'. Then this string has two indexes which can be only represented by integers 0, 1 or -1, -2. But what if we do this instead?
a = 'hi'
print(a['first_name'])
It will throw an error here because, indexes of a string as you might observe here cannot be a string.
Also another problem here is that from your code it seems like you require to loop over informations of multiple such users, but here you are doing it over a single user. To define it for multiple users, you need to define a larger dictionary with these dictionaries of user info as sub dictionaries. Like so-:
users = {
{
'first_name': 'den',
'last_name': 'elc',
'age': '16',
'city': 'slovakia',
},
{
'first_name': 'den_2',
'last_name': 'elc_2',
'age': '19',
'city': 'romania',
},
}
Now the old code of yours iterating over the items of this dict will work all fine!
for user, user_info in users.items():
nameo = user_info['first_name']
namei = user_info['last_name']
age = user_info['age']
city = user_info['city']
print(f"\tFirst name:{nameo}")
print(f"\tLast_name:{namei}")
print(f"\tAge:{age}")
print(f"\tCity:{city}")