object WC {
def main(args: Array[String]): Unit = {
val list = Source.fromFile("E:/words.txt").getLines().toList
.map((_,1))
.groupBy(_._1)
.mapValues(_.map(_._2).reduce(_+_))
list.foreach(println(_))
val l = List(1,2,3,4,5,6,7,8,9)
val sum = l.reduce{_+_}
println("sum=>"+sum)
def main(args: Array[String]): Unit = {
val list = Source.fromFile("E:/words.txt").getLines().toList
.map((_,1))
.groupBy(_._1)
.mapValues(_.map(_._2).reduce(_+_))
list.foreach(println(_))
val l = List(1,2,3,4,5,6,7,8,9)
val sum = l.reduce{_+_}
println("sum=>"+sum)
}
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))
}