Re: Processing list
Kim Trang Le <[email protected]>
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <[email protected]> |
Dear all, I have difficulty processing a list a Scala: Currently I have a list of like this (List(JString(2437), JString(2445), JString(2428), JString(321)), CompactBuffer((4,1))) and I would like after processing, the result will look like below: ( (2437, CompactBuffer((4,1))), (2445, CompactBuffer((4,1))), (2428, CompactBuffer((4,1))), (321, CompactBuffer((4,1))) ) I have got a helpful reply but I am still got stuck when I try this val pair = (List(JString(2437), JString(2445), JString(2428), JString(321)), CompactBuffer((4,1)))val result = pair._1.map((_, pair._2)) First, pair._1 gets the list from the tuple. Then, map performs the function on each element of the list. The function (_, pair._2) puts the given element from the list in a new tuple together with the second part of the pair tuple. I got an error: value _1 is not a member of org.apache.spark.rdd.RDD[(String, Array[(Int, Int)])]. It seems that List(JString(2437), JString(2445), JString(2428), JString(321 )) is a string rather than a list. Can anybody help me with that? Thank you very much. Vào 18:21:17 UTC+7 Thứ Tư, ngày 07 tháng 10 năm 2015, Kim Trang Le đã viết: > > Dear all, I have difficulty processing a list a scala: > Currently I have a list of like this > > (List(JString(2437), JString(2445), JString(2428), JString(321)), > CompactBuffer((4,1))) > > and I would like after processing, the result will look like below: > > ( (2437, CompactBuffer((4,1))) , (2445, CompactBuffer((4,1))) , (2428, > CompactBuffer((4,1))), (321, CompactBuffer((4,1))) ) > > Can any body help me with this issue? > Thank you very much. > -- You received this message because you are subscribed to the Google Groups "scala-language" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.