簡體   English   中英

打印嵌套列表,在一行代碼中選擇所有特定項目

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

我試圖用一行打印代碼打印所有有“A”的學生。 我究竟做錯了什么?

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

這是蟒蛇? 你可以這樣做:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM