标签:scala wordcount map groupby
val str="a aa aaa b a bb c" val middData=List(("a",1),("a",12),("b",3),("c",1),("b",1)) /* * wordcount */ str.split(" ").groupBy(x=>x).map(x =>x._1->x._2.size) /* result: scala.collection.immutable.Map[String,Int] = Map(a -> 2, b -> 1, c -> 1, aa -> 1, bb -> 1, aaa -> 1) */ middData.groupBy(x=>x._1).map(x => x._1->x._2.map(_._2).sum) /* result: scala.collection.immutable.Map[String,Int] = Map(b -> 4, a -> 13, c -> 1) */
标签:scala wordcount map groupby
原文地址:http://9180533.blog.51cto.com/9170533/1566771