Scala Spark:如何比较两个元组清单
我想发现我的第一个阵列中的每个元组是否存在于我的第二个元组中。 如果不是这种情况,我想返回所有与不匹配的元组以及元素的哪个元素完全不匹配。
可能是: 对于firstArray
中的每个元素(x,y): 对于secondarray
中的每个元素(k,z): 如果(x!= k)打印(某物) 返回(x,y) 如果(y!= z)打印(某物) 返回(x,y) 示例:
val firstArray: Array[(String,String)] = Array(("elem1","elem2"), ("elem3","elem4"))
val secondArray: Array[(String,String)] = Array(("elem1","elem2"), ("elem5","elem4"), ("elem3","elem7"))
所需的输出 输出:
("elem3","elem4") is eliminated because elem4 doesn't match elem7
val result: Array[(String,String)] = Array(("elem3","elem4"))
I would like to find if each Tuple in my firstArray exists in my secondArray of tuple.
If it is not the case, i would like to return all tuple that doesn't match and which element of tuple exactly doesn't match.
It could be something like :
for each element (x,y) in firstArray
:
for each element (k,z) in secondArray
:
if (x != k) print(something)
return (x,y)
if (y != z) print(something)
return (x,y)
Example:
val firstArray: Array[(String,String)] = Array(("elem1","elem2"), ("elem3","elem4"))
val secondArray: Array[(String,String)] = Array(("elem1","elem2"), ("elem5","elem4"), ("elem3","elem7"))
Desired output
Output:
("elem3","elem4") is eliminated because elem4 doesn't match elem7
val result: Array[(String,String)] = Array(("elem3","elem4"))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试类似的内容
将返回第二个数组中不存在的第一个数组的元素。
编辑
以下代码将在两个阵列上循环,并比较元组
希望这会有所帮助
you can try something like
It will return the elements of first array that are not present in the second.
Edit
The following code will loop over the two arrays, and compare the tuples
Hope this will help