I need to generate all the arrangements of digits for a number, hopefully with itertools
because it's a 15 digit number (277,777,788,888,899), and will have over 1 million permutations.
If I were to try it with itertools.permutations()
I would get 1,307,674,368,000 numbers, instead of the real ones I need, wich are just 1,261,260.
Without discarding the repeated ones from itertools
, is there an efficient way to just get them the first time?
Current Result:
>>> [''.join(i) for i in itertools.permutations('moon')]
['moon', 'mono', 'moon', 'mono', 'mnoo', 'mnoo', 'omon', 'omno', 'oomn', 'oonm', 'onmo', 'onom', 'omon', 'omno', 'oomn', 'oonm', 'onmo', 'onom', 'nmoo', 'nmoo', 'nomo', 'noom', 'nomo', 'noom']
Expected result:
>>> [''.join(i) for i in itertools.permutations('moon')]
['moon', 'mono', 'mnoo', 'omon', 'omno', 'oomn', 'oonm','onom', 'onmo', 'nmoo', 'nomo', 'noom']