我有这种类型的数据结构:
Array(((10359,60),80), ((10442,54),80), ((10440,61),90), ((10324,63),80), ((10286,35),100), ...
我想得到
Array((10359,60,80), (10442,54,80), (10440,61,90), (10324,63,80), (10286,35,100), ...
val maxData = mappedData.reduceByKey((x,y) => math.max(x, y))
减少之后,我需要获得正确的打印格式,并且可以 找不到正确的方法。
val modifiedData = maxData.map(line => (? , ? ,?))?
答案 0 :(得分:6)
val modifiedData = maxData.map(line => (line._1._1,line._1._2,line._2))
答案 1 :(得分:0)
你正在寻找展平。
scala> val lol = List(List(1,2), List(3,4))
lol: List[List[Int]] = List(List(1, 2), List(3, 4))
在此列表列表上调用flatten方法会创建一个新列表:
scala> val result = lol.flatten
result: List[Int] = List(1, 2, 3, 4)
https://www.safaribooksonline.com/library/view/scala-cookbook/9781449340292/ch10s16.html