将列表拆分为多个列表

时间:2016-06-19 23:18:55

标签: scala scala-collections

我有以下列表:

List("Chapter 1", "2", "This is a sentence", "English")

我想把它拆分如下:

List("Chapter 1", "2", "This", "English")
List("Chapter 1", "2", "is", "English")
List("Chapter 1", "2", "a", "English")
List("Chapter 1", "2", "sentence", "English")

1 个答案:

答案 0 :(得分:2)

val list = List("Chapter 1", "2", "This is a sentence", "English")
list(2).split(" ").map(x => list.patch(2, List(x), 1))