Код: Выделить всё
list1 = [
{'name': 'one', 'email': '[email protected]', 'phone': '111'},
{'name': 'two', 'email': '[email protected]', 'phone': '111'},
{'name': 'three', 'email': '[email protected]', 'phone': '333'},
{'name': 'four', 'email': '[email protected]', 'phone': '444'},
]
list2 = [
{'first_name': 'three', 'email': '[email protected]', 'phone_number': '333'},
{'first_name': 'four', 'email': '[email protected]', 'phone_number': '444'},
{'first_name': 'five', 'email': '[email protected]', 'phone_number': '555'},
]
Код: Выделить всё
list1_only = list(set([x['phone'] for x in list1]) - set([x['phone_number'] for x in list2]))
Код: Выделить всё
['111']
Код: Выделить всё
[
{'name': 'one', 'email': '[email protected]', 'phone': '111'},
{'name': 'two', 'email': '[email protected]', 'phone': '111'}
]
Код: Выделить всё
for l in list1:
for d in diff:
if d == l['phone']:
print(l)
Код: Выделить всё
[x for x in list2 if x['phone_number'] not in list1]
Есть ли однострочные способы замены на list1_only = list(set([x[' телефон'] для x в списке1]) - set([x['phone_number'] для x в списке2]))?
Подробнее здесь: https://stackoverflow.com/questions/790 ... ctionaries