[英]unpivot a map/list/tuples using scala
I have something like this: 我有这样的事情:
val m1 = Map(A -> List(("a","b"),("c","d"),("e","f")))
I want the result to be : 我希望结果是:
(Map(A -> List("a","b")), Map(A -> List ("c","d")), Map(A -> List("e","f")))
could anyone help? 有人可以帮忙吗?
Thanks 谢谢
It's hard to tell what exactly you are trying to do, but here is a way to convert m1
to the desired structure: 很难说出您到底想做什么,但是这是一种将m1
转换为所需结构的方法:
val m1 = Map("A" -> List(("a","b"),("c","d"),("e","f")))
m1.toList.flatMap { case (key, tuple) =>
tuple.map(v => Map(key -> List(v._1, v._2)))
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.