Home > Mobile >  itertools.permutations not working when repetition is above 9
itertools.permutations not working when repetition is above 9

Time:12-24

Why does python itertools.permutations not work when repetition is above 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

CodePudding user response:

range(1, 10) contains 9 elements, the ints from 1 through 9 inclusive. How can the function return a 10-element permutation of a 9-element sequence? Well, it can't, so it doesn't yield anything in that case.

Which means it does work: it yields nothing, which is the correct thing to do.

  • Related