Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala: List of pairs to pair of lists

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?

like image 666
Electric Monk Avatar asked Oct 29 '12 16:10

Electric Monk


1 Answers

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))
like image 122
Kim Stebel Avatar answered Oct 24 '22 23:10

Kim Stebel