I want only values from list inside nested dictionary.
Please advise whether I can print it directly rather than using a for loop.
dict_st={
"students": [
{
"firstName": "Alex",
"lastName": "Rodriguez"
},
{
"firstName": "David",
"lastName": "Crosby"
},
{
"firstName": "Anna",
"lastName": "Weston"
}
]
}
for key, value in dict_st.items():
for key1 in value:
print ( key1["firstName"] )
OUTPUT:
Alex
David
Anna
I am looking for doing it one liner print statment something like below. Is this possible?
print ( dict_st["students"][0] )
OUTPUT:
{'firstName': 'Alex', 'lastName': 'Rodriguez'}
I am looking only "Alex" to be printed in single print statement.
>Solution :
It’s easy:
print ( dict_st["students"][0]["firstName"] )