gpt4 book ai didi

list - Groovy 压缩列表或按级别展平

转载 作者:行者123 更新时间:2023-12-01 00:59:33 24 4
gpt4 key购买 nike

我正在尝试压缩两个列表。我使用 transpose 找到了解决方案(来自此链接: Is there any analog for Scala 'zip' function in Groovy? )但结果并不完全符合我的预期。我想压缩列表!我的意思是压缩。

鉴于:

a = [ [1,2,3] , [4,5,6], [7,8,9] ]
b = [ ['a','b','c'] , ['d','e','f'], ['g','h','j']]

预期结果:
zipped = [ [1,2,3], 
['a','b','c'],
[4,5,6],
['d','e','f'], (...) ]

但是转置给了我:
[a,b].transpose() = [ [[1,2,3],['a','b','c']]
[[4,5,6],['d','e','f']]
[[7,8,9],['g','h','j']] ]

我试图以某种方式压平最后一个列表,但没有按级别压平。每个列表都被扁平化,我只想摆脱“行”列表,

最佳答案

[a, b].transpose().collectMany { it }

关于list - Groovy 压缩列表或按级别展平,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24692690/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com