How to correctly get all combinations of numbers in Python
📁 python, ии
Here is the code:
import itertoolsfor i in itertools.combinations_with_replacement('0123456789', 4): print(''.join(i))I need to get all combinations of digits by 4 with repetitions. Part of the program output:
00000001000200030004000500060007000800090011001200130014001500160017001800190022002300240025Tell me, why after 0009 comes 0011, and not 0010? Also with 0022.
And if in one line using lambda function:
from itertools import chaindivs = lambda n: chain(*((d, n // d) for d in range(1, int(n ** 0.5) + 1) if n % d == 0))print(list(divs(1568)))Result:
[1, 1568, 2, 784, 4, 392, 7, 224, 8, 196, 14, 112, 16, 98, 28, 56, 32, 49]Update, more verbose version:
Log in to leave an answer