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 exactly is the error message you get? From what I can tell, that should work as expected. > Another query. What will be the difference between the following tuples > when created: / > val > input=sc.parallelize(List(("abc",List(1,2,3,4)),("def",List(5,6,7,8)))) / > / > val input=sc.parallelize(List(("abc",(1,2,3,4)),("def",(5,6,7,8)))) / > > Is there a difference in how (1,2,3,4) and List(1,2,3,4) is handled? Well, the difference is that (1, 2, 3, 4) is a Tuple4 instead of a List. In Scala, Tuples have some things in common with Lists and some differences. You can probably find some discussion about that via a web search. Depending on what you're trying to do, you'll prefer one or the other. I believe in the example you gave before, you want List since reduce is not defined for Tuples. Hope this helps, Robert Dodier -- View this message in context: http://apache-spark-user-list.1001560.n3.nabble.com/Calculate-sum-of-values-in-2nd-element-of-tuple-tp25865p25866.html Sent from the Apache Spark User List mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@spark.apache.org For additional commands, e-mail: user-h...@spark.apache.org