Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

itertools.permutations not working when repetition is above 9

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading