Manipulate dictionaries within other dictionaries

-1
Alunos = {
    111: {
        'nome' : 'Joao',  
        'curso' : 'ADS'
    },

    222: { 
        'nome' : 'Pedro',
        'curso' : 'SI'
    },

    333: { 
        'nome' : 'Maria',
        'curso' : 'SI'
    }
}

I need to make a script to show the names of students whose course is YES. I am not being able to have logic and the teacher did not teach it, I already looked for in the internet and I did not obtain anything to give a light.

    
asked by anonymous 18.05.2018 / 02:27

1 answer

1

Just filter the dictionary values based on the course, getting the name of each student:

nomes = (aluno['nome'] for aluno in Alunos.values() if aluno['curso'] == 'SI')

And, to display the names:

for nome in nomes:
    print(nome)

What would it display:

Pedro
Maria

See working at Repl.it | Ideone | GitHub GIST

    
18.05.2018 / 02:50