gpt4 book ai didi

python - 从两个列表中提取相同的元素

转载 作者:行者123 更新时间:2023-12-01 05:11:59 26 4
gpt4 key购买 nike

给定两个列表

a = [1,2,3,4,5]
b = [2,4,6,7]

输出相似元素

c = [2,4]

是否有 API 可以从两个列表中比较和提取相似元素?可以通过逐个元素比较来做到这一点,但我想知道是否已经有API。

最佳答案

print set(a).intersection(set(b))

使用交集获取两个列表中的公共(public)元素

关于python - 从两个列表中提取相同的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24038387/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com