如何删除list1和list2中的重复dicts,并合并到一个新的list_all?

时间:2016-12-16 04:23:39

标签: python list dictionary

list1 = [{'name': 'Tom', 'score':90}, {'name': 'Jack', 'score':86}, {'name': 'Lisa', 'score':81}, {'name': 'Bill', 'score':70}]

list2 = [{'name': 'Jack', 'score':86}, {'name': 'Bill', 'score':70}, {'name': 'Bob', 'score':48}]

如何删除list1和list2中的重复dicts(保持分数顺序),合并到一个新的list_all,并将重复的dicts移动到list_new中?

list_all = [{'name': 'Tom', 'score':90}, {'name': 'Jack', 'score':86}, {'name': 'Lisa', 'score':81}, {'name': 'Bill', 'score':70}, {'name': 'Bob', 'score':48}]

list_new = [{'name': 'Jack', 'score':86}, {'name': 'Bill', 'score':70}]

0 个答案:

没有答案