I have a List[Int]
from 1 to 10 and want to make a List[List[Int]]
containing two List[Int]
: one list containing even numbers and the other containing odd numbers. The result should be like this:
List(List(2,4,6,8,10),List(1,3,5,7,9))
I tried these things:
1.to(10).toList.span((x:Int) => x % 2 == 0)
and
val lst = 1.to(10).toList; lst span (_%2==0)
However, neither of these worked.
Can someone help me on this matter?