Input:
Val l= List("k1","v1","k2","v2")
Desired output:
List(("k1","v1"),("k2","v2"))
I have tried using zip,folding, slicing but no luck.
Note:I have done it in python but couldn't able to do in scala.
Input:
Val l= List("k1","v1","k2","v2")
Desired output:
List(("k1","v1"),("k2","v2"))
I have tried using zip,folding, slicing but no luck.
Note:I have done it in python but couldn't able to do in scala.
I would do this like this:
However, it would be perfectly doable without
grouped
:or
Of course if performance was really critical I would implement it in slightly different way to avoid allocations (e.g. by prepending results in foldLeft and reversing final results, or by using tailrec or ListBuffer).