【问题标题】:processing row combinations from a array and output in multiple arrays处理来自数组的行组合并在多个数组中输出
【发布时间】:2012-04-25 19:10:53
【问题描述】:

我有一个这样的值数组:

0129 4589 4878 7895

我想遍历整个数组并在每一轮中留出一行来得到这个:

0129 4589 4878

0129 4589 7895

0129 4878 7895

4589 4878 7895

....等等

我知道 python 中的 itertools '组合'。有没有我可以将函数应用于数组的整行而不是行的单个值?

【问题讨论】:

  • 什么是“行”?什么是“数组”?你可以说得更详细点吗?贴一些代码。

标签: python arrays combinations


【解决方案1】:

你有我认为的答案

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)]

【讨论】:

  • 非常感谢!这很有帮助,我刚刚重新思考了一个函数。
猜你喜欢
  • 2021-05-18
  • 1970-01-01
  • 2021-12-09
  • 2013-03-30
  • 1970-01-01
  • 1970-01-01
  • 2016-04-02
  • 1970-01-01
  • 2019-12-31
相关资源
最近更新 更多