[英]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.我试图用一行打印代码打印所有有“A”的学生。 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']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.