取两个数组,从非唯一的值创建第三个数组

时间:2022-09-05 19:15:47

I'm attempting to de-dupe an enormous email list migration, however there's a catch. I'd like to take the duplicates and turn them into their own array (3rd).

我正试图消除一个巨大的电子邮件列表迁移,然而有一个陷阱。我想把这些复制的东西变成他们自己的数组(3)。

Lets make these arrays very simple, and short.

让我们使这些数组变得非常简单和简短。

a = ["rich@aol.com", "ian@aol.com"]
b = ["rich@aol.com"] 

Essentially i'm trying to make c = ["rich@aol.com"] because it's the only email that resides on both lists.

本质上,我试图使c = ["rich@aol.com"]因为它是两个列表中唯一的电子邮件。

What I've attempted so far:

我到目前为止的尝试:

Is there an opposite to unqiq ?

unqiq有反义词吗?

ab = a + b
ab.uniq

returns: ["rich@aol.com", "ian@aol.com"]

返回:[“rich@aol.com”、“ian@aol.com”]

Could I dump a + b into a third c array, and compare c to ab.uniq to get what's duplicated?

我是否可以将a + b转储到第三个c数组中,并将c与ab.uniq进行比较以得到复制的结果?

Am i missing an easier way to do this? Any help will be much appreciated!!!!

我是不是错过了一个更简单的方法?如有任何帮助,我们将不胜感激!!!

1 个解决方案

#1


6  

You want the intersection of the arrays.

你想要数组的交集。

c = a & b

#1


6  

You want the intersection of the arrays.

你想要数组的交集。

c = a & b