【发布时间】:2019-05-06 16:22:32
【问题描述】:
我正在尝试计算 itertools.product() 的第 n 个结果
test = list(product('01', repeat=3))
print(test)
desired_output = test[0]
print(desired_output)
所以而不是得到:
[('0', '0', '0'), ('0', '0', '1'), ('0', '1', '0'), ('0', '1', '1'), ('1', '0', '0'), ('1', '0', '1'), ('1', '1', '0'), ('1', '1', '1')]
我想得到:
('0', '0', '0')
但是,正如您可能已经猜到的那样,它不能很好地扩展。这就是为什么我试图只计算第 n 个值。
我通读了 Nth Combination 但我需要 product() 提供的重复功能
提前致谢!
【问题讨论】:
标签: python python-3.x combinations itertools combinatorics