I have the following 2 lists:
val a = List(List(1,2,3),List(2,3,4),List(3,4,5))
val b = List(1,2,3)
I want to filter elements in a
that contain an element in b
and add them to a Map like so:
Map(1 -> List(List(1, 2, 3)), 2 -> List(List(1, 2, 3), List(2, 3, 4)), 3 -> List(List(1, 2, 3), List(2, 3, 4), List(3, 4, 5)))
I tried the following:
b.map(x => Map( x -> a.filter(y => y contains x)))
but it gives me
List(Map(1 -> List(List(1, 2, 3))), Map(2 -> List(List(1, 2, 3), List(2, 3, 4))), Map(3 -> List(List(1, 2, 3), List(2, 3, 4), List(3, 4, 5))))
How do I flatten this into a single Map? Is my approach wrong?