我有两个清单 -
A = (("192.168.1.1","private","Linux_server","str1"),
("192.168.1.2","private","Linux_server","str2"))
B = ("A","B")
我想要关注输出
outputList = (("192.168.1.1","private","Linux_server","str1", "A"),
("192.168.1.2","private","Linux_server","str2","B"))
我想将第二个列表元素作为列表序列插入到第一个列表中。
两个列表大小始终相同。
如何使用scala获得以上输出?
答案 0 :(得分:3)
答案简短:
A = (A zip B).map({ case (x, y) => x :+ y })
某些编译代码更明确:
val a = List(
List("192.168.1.1", "private", "Linux_server", "str1"),
List("192.168.1.2", "private", "Linux_server", "str2")
)
val b = List("A", "B")
val c = List(
List("192.168.1.1", "private", "Linux_server", "str1", "A"),
List("192.168.1.2", "private", "Linux_server", "str2", "B")
)
assert((a zip b).map({ case (x, y) => x :+ y }) == c)