黑松山资源网 Design By www.paidiu.com
①差集
方法一:
if __name__ == '__main__': a_list = [{'a' : 1}, {'b' : 2}, {'c' : 3}, {'d' : 4}, {'e' : 5}] b_list = [{'a' : 1}, {'b' : 2}] ret_list = [] for item in a_list: if item not in b_list: ret_list.append(item) for item in b_list: if item not in a_list: ret_list.append(item) print(ret_list)
执行结果:
方法二:
if __name__ == '__main__': a_list = [{'a' : 1}, {'b' : 2}, {'c' : 3}, {'d' : 4}, {'e' : 5}] b_list = [{'a' : 1}, {'b' : 2}] ret_list = [item for item in a_list if item not in b_list] + [item for item in b_list if item not in a_list] print(ret_list)
执行结果:
方法三:
if __name__ == '__main__': a_list = [1, 2, 3, 4, 5] b_list = [1, 4, 5] ret_list = list(set(a_list)^set(b_list)) print(ret_list)
执行结果:
注:此方法中,两个list中的元素不能为字典
②并集
if __name__ == '__main__': a_list = [1, 2, 3, 4, 5] b_list = [1, 4, 5] ret_list = list(set(a_list).union(set(b_list))) print(ret_list)
执行结果:
注:此方法中,两个list中的元素不能为字典
③交集
if __name__ == '__main__': a_list = [1, 2, 3, 4, 5] b_list = [1, 4, 5] ret_list = list((set(a_list).union(set(b_list)))^(set(a_list)^set(b_list))) print(ret_list)
执行结果:
注:此方法中,两个list中的元素不能为字典
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
更新日志
2024年10月09日
2024年10月09日
- s14全球总决赛瑞士轮赛制是什么 全球总决赛瑞士轮赛制详情
- 《COD21》全新剧情宣传片:10月25日XGP见!
- 美国拳王家门口身中7枪遇害 年仅31岁凶手仍未被逮捕
- 《寂静岭2》重制版光追对比:氛围更加恐怖
- 林慧萍.1982-往昔(飞跃复刻版)【歌林】【WAV+CUE】
- 陈楚生.2007-原来我一直都不孤单(EP)【天娱传媒】【WAV+CUE】
- 罗嘉良.1986-秦始皇(2014环球复黑王·百代篇)【EMI百代】【WAV+CUE】
- 2024周年庆赠送物品介绍,周年庆送什么
- 【原神】V5.0攻略 |「明黄曜石断片」全收集
- 【原神】V5.0攻略 | 隐藏成就「烦请高抬贵脚」达成
- 证声音乐图书馆《蔚蓝海岸·爵士度假日》[FLAC/分轨][155.47MB]
- 腾讯音乐人《浪漫火焰(新势力计划合辑 Vol.11)》[320K/MP3][56.91MB]
- 腾讯音乐人《浪漫火焰(新势力计划合辑 Vol.11)[FLAC/分轨][147.45MB]
- 2024年,哪里还可以玩有趣的魔兽RPG?
- 类银河恶魔城动作游戏《灵魂熔解》已正式登陆Steam