我有一个像这样的值数组:
0129 4589 4878 7895
我想迭代整个数组,并在每一轮中留下一行以得到以下结果:
0129 4589 4878
0129 4589 7895
0129 4878 7895
4589 4878 7895
...等等
我知道 python 中的 itertools“组合”。我是否可以将函数应用于数组的整行而不是行的各个值?
最佳答案
我想你已经有了答案
itertools.combinations(array, 3)
会产生这个输出
即,
>>> [x for x in itertools.combinations([123,345,543,234],3)]
[(123, 345, 543), (123, 345, 234), (123, 543, 234), (345, 543, 234)]
关于python - 处理数组中的行组合并输出多个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10322222/