简体   繁体   中英

print nested list selecting specific items all in one line of code

I'm trying to print all the students that have "A" with one line of print code. What am I doing wrong?

students = [["Will", "B"], ["Kate", "B"], ["Max", "A"], 
["Elsa", "C"], ["Alex", "B"], ["Chris", "A"]]
print([dict(students)],(for v in [dict(students)]).items()=='A')

This is python? You can just do:

[keys for keys,values in dict(students).items() if values == 'A']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM