在 Python 中,我可以使用 itertools.product()
,文档中说它是“笛卡尔积,相当于嵌套的 for 循环”。
它在 Perl 中的等价物是什么?
Python 中的示例:
import itertools
opts_list = [["A","B"], ["C","D","E"], ["F","G"]]
print list(itertools.product(*opts_list))
给予:
[('A', 'C', 'F'), ('A', 'C', 'G'), ('A', 'D', 'F'), ('A', 'D', 'G'), ('A', 'E', 'F'), ('A', 'E', 'G'), ('B', 'C', 'F'), ('B', 'C', 'G'), ('B', 'D', 'F'), ('B', 'D', 'G'), ('B', 'E', 'F'), ('B', 'E', 'G')]
最佳答案
我最终使用了:
use Math::Cartesian::Product;
cartesian {print "@_\n"} ["A","B"], ["C", "D", "E"], ["F", "G"];
关于Perl 中的 Python itertools.product() 等价物,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29215233/