【问题标题】:make all arrays from list of arrays in python从python中的数组列表中制作所有数组
【发布时间】:2019-09-16 14:15:47
【问题描述】:

我有一个数组列表

any_array = [[0,1],[1,2,3],[2,6]]

我需要获取所有数组,其中第一个数字是[0,1] 中的任意数字,第二个数字来自[1,2,3],第三个数字来自[2,6] 例如 [0,1,2],[1,3,6]等 我应该如何在python中解决这个问题?

【问题讨论】:

标签: python arrays python-3.x list sorting


【解决方案1】:

这称为笛卡尔积itertools 已经包含一个函数

from itertools import product

result = []

for p in product(*x):
    result.append(list(p))

【讨论】:

猜你喜欢
  • 2018-05-11
  • 1970-01-01
  • 1970-01-01
  • 2015-01-16
  • 1970-01-01
  • 2014-04-01
  • 2023-01-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多