は、私は、辞書のリストを持っている:dictsのリストでは、1つのキー/値に基づいてdictを一致させますか? Pythonで
mylist = [ { 'name': 'James', 'school': 'UCLA', 'date_joined': 2001 },
{ 'name': 'Jack', 'school': 'UCLA', 'date_joined': 2001 },
{ 'name': 'Fisher', 'school': 'NYU', 'date_joined': 2003 }]
は、どのように私は、特定の辞書はのみ名前と学校のキー/値に基づいて、既存のレコードと一致するかどうかを確認することができますか?だから、
:
example1 = { 'name': 'James', 'school': 'UCLA', 'date_joined': 2007 }
example1 = { 'name': 'James', 'school': 'UCLA', 'date_joined': 2001 }
が両方一致する必要がありますが、
example3 = { 'name': 'James', 'school': 'MIT', date_joined': 2001 }
はいけません。
明らかにあります:
for m in myList:
if (m['name']==example['name'] and m['school']==example['school']):
match_found = True
continue
が、よりコンパクトな方法はありますか?あなたのプログラムの構造についての詳細は何も知らない
をしますが、別の[を使用して検討するかもしれませんデータ構造](http://stackoverflow.com/questions/6479377/in-list-of-dicts-match-dict-based-on-one-key-value/6479532#6479532)。 – senderle