【问题标题】:itertools.permutations not working when repetition is above 9当重复次数高于 9 时,itertools.permutations 不起作用
【发布时间】:2021-12-24 06:20:04
【问题描述】:

为什么python itertools.permutations在重复次数超过9时不起作用?

for i in itertools.permutations(range(1, 10), 9):
    print(i) # works

for i in itertools.permutations(range(1, 10), 10):
    print(i) # does not work

【问题讨论】:

标签: python itertools


【解决方案1】:

range(1, 10) 包含 9 个元素,包括从 1 到 9 的整数。函数如何返回 9 元素序列的 10 元素排列?好吧,它不能,所以在这种情况下它不会产生任何东西。

这意味着它确实起作用了:它什么也没产生,这是正确的做法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-04
    • 2011-09-25
    • 2018-04-05
    • 2015-04-06
    • 2014-02-16
    • 2018-08-14
    相关资源
    最近更新 更多