Get information inside a dictionary

Asked

Viewed 30 times

-1

I’m having a question regarding a dictionary in a dictionary, I have a code that has multiple users on a website,each with a unique name and age, where the names of users and ages are used in keys in a dictionary. how do I access the nome, sobrenome and idade through a bond.

usuarios = {
    'jsilva': {
        'nome': 'junior',
        'sobrenome': 'silva',
        'idade': 18,
    },
    'rmatheus': {
        'nome': 'roberto',
        'sobrenome': 'matheus',
        'idade': 20,
    },
}

1 answer

-2


To display the information inside a dictionary I did as follows

for usuario, usuario_info in usuarios.items():
    print("\nUsuário: " + usuario)
    nome_completo = usuario_info['nome'] + " " + usuario_info['sobrenome']
    idade = usuario_info['idade']

    print("Nome completo: " + nome_completo.title())
    print("Idade: " + str(idade))
  • 1

    the . title() serves to leave the words as certain titles, and as it does to leave the full name in all uppercase?

  • 1

    using the upper method()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.