jimitkr wrote
> I've tried fold, reduce, foldLeft but with no success in my below code to
> calculate total:
/
> val valuesForDEF=input.lookup("def")
> val totalForDEF: Int = valuesForDEF.toList.reduce((x: Int,y:
> Int)=>x+y)
> println("THE TOTAL FOR DEF IS" + totalForDEF)
/
Hmm, what
For the first one,
input.map { case(x,l) => (x, l.reduce(_ + _) ) }
will do what you need.
For the second, yes, there's a difference, one is a List the other is a
Tuple. See for instance
See for instance
val a = (1,2,3)
a.getClass.getName
res4: String = scala.Tuple3
You should look up tuples
Hi,
I've created tuples of type (String, List[Int]) and want to sum the values
in the List[Int] part, i.e. the 2nd element in each tuple.
Here is my list
/ val
input=sc.parallelize(List(("abc",List(1,2,3,4)),("def",List(5,6,7,8/
I want to sum up values in the 2nd element of the tuple so