}
def WC(): Unit = { val list = Source.fromFile("E:/words.txt").getLines().toList .map { x => (x,1) } .groupBy(x=>x._1) .mapValues{ list=>list.map(i=>i._2).reduce((x,y)=>x+y) } list.foreach(x=>println(x)) } def WC2(): Unit = { val list = Source.fromFile("E:/words.txt").getLines().toList .map { x => (x,1) } .groupBy(x=>x._1) .mapValues(list=>list.map(i=>i._2)) .mapValues(l => l.reduce((x,y)=>x+y)) list.foreach(x=>println(x)) }
}