我有Array[(List(String)), Array[(Int, Int)]]
这样的
((123, 456, 789), (1, 24)) ((89, 284), (2, 6)) ((125, 173, 88, 222), (3, 4))
我想将第一个列表的每个元素分发到第二个列表,就像这样
(123, (1, 24)) (456, (1, 24)) (789, (1, 24)) (89, (2, 6)) (284, (2, 6)) (125, (3, 4)) (173, (3, 4)) (88, (3, 4)) (22, (3, 4))
谁能帮我这个?非常感谢你.
对于输入数据定义如下:
val data = Array((List("123", "456", "789"), (1, 24)), (List("89", "284"), (2, 6)), (List("125", "173", "88", "222"), (3, 4)))
您可以使用:
data.flatMap { case (l, ii) => l.map((_, ii)) }
产量:
Array[(String, (Int, Int))] = Array(("123", (1, 24)), ("456", (1, 24)), ("789", (1, 24)), ("89", (2, 6)), ("284", (2, 6)), ("125", (3, 4)), ("173", (3, 4)), ("88", (3, 4)), ("222", (3, 4)))
我认为这符合您的要求.