如何在两个不同的数据列之间提取非唯一数据?

问题描述 投票:0回答:1

这是数据。

 col="a","b","c","d"
 col1="a","b","c","g","q"

我想要的输出是

 'd','g','q'

我该怎么做?

python python-3.x
1个回答
1
投票

您可以在此处使用^集的对称差。

col="a","b","c","d"
col1="a","b","c","g","q"

print(set(col)^set(col1))
# {'d', 'g', 'q'}
© www.soinside.com 2019 - 2024. All rights reserved.