我正在尝试计算 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 个值。
我通读了第 N 个组合 https://stackoverflow.com/questions/1776442/nth-combination但我需要 Product() 提供的重复功能
提前致谢!