Skip to content

Commit 1f47a13

Browse files
committed
itertools: add product() implementation
1 parent 8e9a12d commit 1f47a13

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

itertools/itertools.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,12 @@ def accumulate(iterable, func=lambda x, y: x + y):
6666
for element in it:
6767
acc = func(acc, element)
6868
yield acc
69+
70+
def product(*args, repeat=1):
71+
if not args:
72+
yield ()
73+
else:
74+
args = args*repeat
75+
for a in args[0]:
76+
for prod in product(*args[1:]):
77+
yield (a,)+prod

0 commit comments

Comments
 (0)