【发布时间】:2012-06-15 05:56:25
【问题描述】:
我有一本看起来像这样的字典:
grades = {
'alex' : 11,
'bob' : 10,
'john' : 14,
'peter': 7
}
还有名单students = ('alex', 'john')
我需要检查students 中的所有名称是否作为grades 字典中的键存在。
grades可以有多个名字,但students中的所有名字都应该在grades中
必须有一个简单的方法来做到这一点,但我还是 python 的新手,无法弄清楚。试过if students in grades,没用。
在实际情况下,列表会更大。
【问题讨论】:
标签: python dictionary