score:2
Accepted answer
as i mentioned in my comment, using either diff
or intersect
probably won't help you solve your problem. there might be something better built in, but if there is not, then you can use logic similar to this (which is in long form so that the different steps are clear):
val l1 = seq( ("a" , 1) , ("b" , 2) , ("c" , 3) )
val l2 = seq( ("a" , 4) , ("d" , 5) , ("c" , 6) )
val m1 = l1.tomap
val m2 = l2.tomap
val differentkeys = m1.keyset.diff(m2.keyset) ++ m2.keyset.diff(m1.keyset)
val result = (l1 ++ l2).filter{
case (k, v) => differentkeys.contains(k)
}
println(result)
Source: stackoverflow.com
Related Query
- Finding uncommon elements in Seq of Tuples
- Add two tuples containing simple elements in Scala
- What is Scala way of finding whether all the elements of an Array has same length?
- Insert an element between each two adjacent elements of Seq
- Finding elements in a scala list and also know which predicate has been satisfied
- How to merge tuples by same elements in Scala
- Scala: Creating a list of tuples from list elements sequentially
- How to sort an RDD of tuples with 5 elements in Spark Scala?
- How to find unique elements from list of tuples based on some elements using scala?
- Scala Seq - accept only elements of the same subtype
- Scala remove elements from list of tuples
- How to swap to elements in Seq
- Flattening arbitrarily nested tuples containing case class elements using Shapeless
- Scala - finding first position in which two Seq differ
- Scala - Merge two lists of tuples by common elements
- Finding overlapping DateTime intervals of elements in multiple lists
- spark scala get uncommon map elements
- Merge the Seq of tuples and iterate over them
- Scala extract from Seq of tuples
- Scala finding elements in big (30MB) xml files
- Seq with maximal elements
- Is there a better way to convert a Seq of "nested" tuples to a hierarchy of maps?
- Scala: Best way to remove tuples from Seq where one value is None
- Simplest way to change multiple elements in a Seq in Scala
- Replace all elements of a Seq from a String
- Finding XML elements that dont have subelements or value in scala
- Scala adding elements to seq and handling futures, maps, and async behavior
- More efficient solution for finding smallest k elements in List
- Scala conditional sum of elements in a filtered tuples list
- How to idiomatically turn a Seq of tuples into a Map in scala?
More Query from same tag
- How to implement a POST-REDIRECT-GET in Play Framework
- Higher kinded type constructor with upper type bounds doesn't work if bound is abstract type member
- Scala: Type-level programming parameterised by nested type value
- Moving a graph of mathematical function
- How do you improve the performance of foldLeft (or scanLeft) when you don't always need to examine all the elements of a list?
- How know which function was assigned?
- Updating element property in scala list buffer
- How to use Scala's singleton-object types?
- Spark Persist method odd behavior
- Hide a particular field of case class while converting to json
- Kstream-Kstream join based on common field
- Spark: PageRank example when iteration too large throws stackoverflowError
- spark scala typesafe config safe iterate over value of a specific column name
- Spark Structured Streaming + Kafka Integration: MicroBatchExecution PartitionOffsets Error
- Merging too many small files into single large files in Datalake using Apache Spark
- Is it possible to install a callback after request processing is finished in Spray?
- IntelliJ Idea 2016.2.4 cannot resolve symbol spark_2.11
- How can I pass this case rule in Scala to only accept string containing letters?
- Using a Java library with Scala reserved words
- Algorithm to define pairs from a list
- How to Decode a Generic Case Class with semiautomatic in Circe
- Scala Aggregate result from multiple Future calls
- How to set up IntelliJ external Scala compiler for Maven projects
- Removing string element off list by index id in Scala
- Scala Slick: cannot find object codegen in package scala.slick.model
- code generation using Treehugger scala
- How to define a custom sbt setting in project/{...}.scala?
- writing script in scala to join two mysql tables and create one object (quill)
- SPARK SCALA Stream ? in output
- Find the duplicate values of an array column in the dataframe in Scala