Given an input n and strings, for example:
3
abc
de
fgh
How can I produce this output, using recursion?
adf
adg
adh
aef
aeg
aeh
bdf
bdg
bdh
bef
beg
beh
cdf
cdg
cdh
cef
ceg
ceh
Given an input n and strings, for example:
3
abc
de
fgh
How can I produce this output, using recursion?
adf
adg
adh
aef
aeg
aeh
bdf
bdg
bdh
bef
beg
beh
cdf
cdg
cdh
cef
ceg
ceh
This can be solved with a regular itertools.product
;
In [20]: list(itertools.product('abc', 'de', 'fgh'))
Out[20]:
[('a', 'd', 'f'),
('a', 'd', 'g'),
('a', 'd', 'h'),
('a', 'e', 'f'),
('a', 'e', 'g'),
('a', 'e', 'h'),
('b', 'd', 'f'),
('b', 'd', 'g'),
('b', 'd', 'h'),
('b', 'e', 'f'),
('b', 'e', 'g'),
('b', 'e', 'h'),
('c', 'd', 'f'),
('c', 'd', 'g'),
('c', 'd', 'h'),
('c', 'e', 'f'),
('c', 'e', 'g'),
('c', 'e', 'h')]