pascalabcnet/InstallerSamples/SPython/py15.pys

12 lines
365 B
Plaintext
Raw Normal View History

2025-08-31 17:21:18 +03:00
def product(a: list[int], **kwargs: int) -> list[list[int]]:
repeat = kwargs['repeat']
if repeat == 1:
return [[a[i]] for i in range(len(a))]
prev = product(a, repeat = repeat - 1)
res: list[list[int]] = []
for elem in a:
for p in prev:
res.append([elem] + p)
return res
print(product([1,2,3], repeat = 3));