我有以下元组:(1,"3idiots",List("Action","Adventure","Horror")我需要转换为以下格式的列表:
List(
(1,"3idiots","Action"),
(1,"3idiots","Adventure")
)
Run Code Online (Sandbox Code Playgroud)
要添加到以前的答案,您还可以在这种情况下使用for-understanding ; 它可能会使事情更清楚恕我直言:
for(
(a,b,l) <- ts;
s <- l
) yield (a,b,s)
Run Code Online (Sandbox Code Playgroud)
所以如果你有:
val ts = List(
("a","1", List("foo","bar","baz")),
("b","2", List("foo1","bar1","baz1"))
)
Run Code Online (Sandbox Code Playgroud)
你会得到:
List(
(a,1,foo),
(a,1,bar),
(a,1,baz),
(b,2,foo1),
(b,2,bar1),
(b,2,baz1)
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
155 次 |
| 最近记录: |