python - n维数组元素的Python组合
问题描述
我有一个数组列表如下
list1 = [['01', '02', '03', '04', '05', '06'], ['01', '64', '2f'], ['00', '1f', '17']]
我需要这些元素的所有可能组合,例如
010100, 01011f, 010117, 010200, 01021f, etc.
解决方案
你可以使用itertools.product
并得到你想要的:
import itertools
list1 = [['01', '02', '03', '04', '05', '06'], ['01', '64', '2f'], ['00', '1f', '17']]
for prd in itertools.product(*list1):
print(''.join(prd))
输出:
010100
01011f
010117
016400
01641f
016417
012f00
...
062f00
062f1f
062f17
推荐阅读
- google-cloud-platform - Cloud Run 获取公共 URL
- r - 从 R 中运行终端命令:显示 SCP 传输的输出
- javascript - 如何避免在父组件状态更新时重新渲染循环中的所有子组件
- x86 - 当预取队列中只剩下 1 个字节时,8086 是否会启动 1 个字节的代码提取?
- heroku - Heroku Pipelines:来自 app.json 的配置被忽略
- serial-port - 树莓派-4;pl2303_read_int_callback - usb_submit_urb 失败,结果为 -1
- css - 无限流文字动画CSS
- c# - 将自动售货机界面构建为控制台应用程序但出现错误 - 无法将双精度值转换为布尔值
- java - 使 Spring Boot JSON 枚举反序列化严格,因此它不会默默地将无效值转换为 null
- javascript - Express.js:在调用 next() 后发送结果