【发布时间】:2016-10-07 21:24:02
【问题描述】:
我在 Scala 中有一个列表列表,看起来像这样:List(List(1, 5, 6, 10), List(1, 6), List(1, 3, 10),我想转换
它进入HashMap[Int, List[Int]],其中第一个 Int 是每个列表的索引,List[Int] 是列表本身。最后 HashMap 应该
看起来像
HashMap[Int, List[Int]](
0 -> List(1, 5, 6, 10),
1 -> List(1, 6),
2 -> List (1, 3, 10),)
这是我的方法,有一个列表 0 到列表的长度,然后用这个嵌套列表压缩它,然后以某种方式
将其转换为 HashMap。但我正在寻找更惯用或更简洁的东西。有什么想法吗?
【问题讨论】: