12

I have a list of pairs:

val pairs = List("a" -> 1, "b" -> 2, "c" -> 3)

I'd like to convert it to a pair of lists:

List("a", "b", "c") -> List(1, 2, 3)

Basically, I want the opposite of zip()

Any elegant way of doing so?

om-nom-nom
  • 62,329
  • 13
  • 183
  • 228
Electric Monk
  • 2,192
  • 2
  • 23
  • 33
  • 4
    ... but mainly, because Kim Stebel loves downvoting people – Luigi Plinge Oct 29 '12 at 19:07
  • 1
    @LuigiPlinge: I don't downvote people, I downvote questions and answers. The people who post them should stop taking it personally. Sadly there is still no way to downvote comments. ;) Besides, I am only one of 3 people who downvoted. – Kim Stebel Oct 30 '12 at 10:43

1 Answers1

18

The opposite of zip? What might that be? unzip maybe?

scala> List("a" -> 1, "b" -> 2, "c" -> 3).unzip
res0: (List[java.lang.String], List[Int]) = (List(a, b, c),List(1, 2, 3))
Kim Stebel
  • 41,826
  • 12
  • 125
  • 142