存在我的字典,這些看起來像這樣:Python的檢查,如果鍵列表字典
grades = {
'alex' : 11,
'bob' : 10,
'john' : 14,
'peter': 7
}
和名稱students = ('alex', 'john')
我需要檢查在students
所有名稱作爲存在的列表鍵字grades
字典。
grades
可以有更多的名字,但在students
所有名稱應該是grades
必須有做一個簡單的方法,但我還是新的蟒蛇,不能弄明白。試過if students in grades
,沒有工作。
在實際情況下,列表會更大。
可能的重複[如何檢查多個鍵在一個字典中的單個傳遞?](https://stackoverflow.com/questions/1285911/how-do-i-check-that-multiple-keys - 在一個字典中的單通) –