今日は時間がないので、関数とか手抜きです。
python
1def eq_dict(a, b):
2 if len(a) != len(b):
3 return False
4 for k in a:
5 try:
6 if a[k] != b[k]:
7 return False
8 except Exception:
9 return False
10 return True
11
12def d_in_l(d, lists):
13 for e in lists:
14 if eq_dict(d, e):
15 return True
16 return False
17
18d1 = [{"name": "佐藤", "age": "13"},{"name": "山下", "age": "15"}]
19d2 = [{"name": "山崎", "age": "18"},{"name": "佐藤", "age": "13"},{"name": "山下", "age": "15"}]
20x = [d for d in d2 if d_in_l(d, d1) == False]
21print(x)
実行結果は以下です。
python
1>>> def eq_dict(a, b):
2... if len(a) != len(b):
3... return False
4... for k in a:
5... try:
6... if a[k] != b[k]:
7... return False
8... except Exception:
9... return False
10... return True
11...
12>>> def d_in_l(d, lists):
13... for e in lists:
14... if eq_dict(d, e):
15... return True
16... return False
17...
18>>> d1 = [{"name": "佐藤", "age": "13"},{"name": "山下", "age": "15"}]
19>>> d2 = [{"name": "山崎", "age": "18"},{"name": "佐藤", "age": "13"},{"name": "山下", "age": "15"}]
20>>> x = [d for d in d2 if d_in_l(d, d1) == False]
21>>> print(x)
22[{'name': '山崎', 'age': '18'}]