list1 = [1, 2, 4]
list2 = [3, 4, 5]
set1 = set(list01) # 将列表转换成集合
set2 = set(list02)
print(set1 & set2) # 相同元素
print(set1 ^ set2) # 不同元素
输出结果为:
{4}
{1, 2, 3, 5}
万水千山总是情,给个打赏行不行。
打赏

list1 = [1, 2, 4]
list2 = [3, 4, 5]
set1 = set(list01) # 将列表转换成集合
set2 = set(list02)
print(set1 & set2) # 相同元素
print(set1 ^ set2) # 不同元素
输出结果为:
{4}
{1, 2, 3, 5}
非特殊说明,本博所有文章均为博主原创。
如若转载,请注明出处:https://xuyu.in/1012.html