# 交集
def list_intersection(list1: list, list2: list) -> list:return list(set(list1).intersection(set(list2)))# 并集
def list_union(list1: list, list2: list) -> list:return list(set(list1).union(set(list2)))# 差集(在in_list中,但是不在not_in_list中)
def list_difference(in_list: list, not_in_list: list) -> list:return list(set(in_list).difference(set(not_in_list)))if __name__ == '__main__':list_1 = ['a', 'b', 'c', 1, 2, 3]list_2 = [1, 2, 3, 4, 5, 6]print("交集:", list_intersection(list_1, list_2))print('并集:', list_union(list_1, list_2))print('差集(在list_1中,但不在list_2中):', list_difference(list_1, list_2))

python取两个列表的并集、交集、差集相关推荐

  1. python求两个列表的并集.交集.差集方法

    求两个列表的差集 >>> a = [1,2,3] >>> b=[1,2] >>> ################################ ...

  2. 使用Set求两个数组的并集|| 交集||差集

    这里要讲解一下,使用Set求两个数组的并集|| 交集||差集. 先定义两个数组: let a = new Set([1, 2, 3]);let b = new Set([4, 3, 2]); 并集 l ...

  3. python 取两/多个list的交集

    python 取两个/多个list的交集 Two List Input: lst1 = [15, 9, 10, 56, 23, 78, 5, 4, 9] lst2 = [9, 4, 5, 36, 47 ...

  4. python取两个set的并集、交集、差集

    文章目录 1. 并集 2. 交集 3. 差集 对于以下两个set x = set([1,2,3]) y = set([2,3,4]) 1. 并集 方法一: x | y 方法二: x.union(y) ...

  5. python中怎么取两个列表 集合的交集

    在python 3.x 版本中 set 中有函数intersection() intersection() 方法用于返回两个或更多集合中都包含的元素,即交集. 语法: 在这里插入代码片set.inte ...

  6. 高级JAVA - 利用函数式接口实现通用的取并集/交集/差集进阶版

    在前文(高级JAVA - 利用函数式接口实现通用的取并集/交集/差集)中我们实现了利用函数式接口获取交集/差集 , 但是只能全部生成 , 假如我们只需要一个交集的话 , 所有代码仍然会执行一次 . 比 ...

  7. 高级JAVA - 利用函数式接口实现通用的取并集/交集/差集

    package com.xing.dto;import com.xing.common.utils.XDataUtil; import lombok.Data;import java.util.Arr ...

  8. Python中将两个列表数据zip起来并遍历(Iterating through two lists in parallel)

    Python中将两个列表数据zip起来并遍历(Iterating through two lists in parallel) 目录 Python中将两个列表数据zip起来并遍历(Iterating ...

  9. Python中将两个列表(list)数据zip起来

    Python中将两个列表(list)数据zip起来 目录 Python中将两个列表(list)数据zip起来

最新文章

  1. Faster R-CNN教程
  2. java四种线程池类型以及可选择的阻塞队列
  3. SQL查询效率:100w数据查询只需要1秒钟
  4. LightGBM参数的贝叶斯搜索(有boost_from_average参数设置)
  5. 递归和分治思想及其应用
  6. python beautifulsoup4 table tr_python BeautifulSoup解析表
  7. java蓝桥杯 试题-基础练习-数列排序
  8. python报表_Python生成报表
  9. iis configuration error
  10. 麻省理工学生令计算机系统升级不需重启
  11. 《jBPM4工作流应用开发指南》这本书
  12. 格雷码的FPGA实现
  13. 鸿蒙系统我的二次元之旅,创世神的二次元
  14. win11java环境配置
  15. java学生成绩统计
  16. React Or Vue
  17. 使用Java在浏览器页面无法导出excel表格
  18. RabbitMQ实战指南之RabbitMQ架构及运转流程
  19. 关于“马甲app”你不得不知的一些常识
  20. 树莓派3b+快速编译opencv成功案例指导(保姆级教程)

热门文章

  1. 判断ip地址的合法性python_使用Python判断IP地址合法性的方法实例
  2. 自动Shader优化器glsl_optimizer的编译与使用
  3. Java23中设计模式(Design Patterns)详解
  4. SQL Server 2012安装配置(Part2 )
  5. 单例设计模式 (2)
  6. iOS CocoaPods安装和使用图解
  7. DDMS连接bluestacks找不到设备
  8. SQL SERVER中关于OR会导致索引扫描或全表扫描的浅析
  9. android 画笔
  10. php自动载入类文件函数,我可以在没有PHP的类中自动加载函数文件吗?