Find All Possible Combinations
I asked this question earlier but regarding another programming languages. Let's say I have a couple roots, prefixes, and suffixes. roots = ['car insurance', 'auto insurance'] pref
Solution 1:
Use itertools.product()
:
for p, r, s in itertools.product(prefix, roots, suffix):
print p, r, s
Solution 2:
There's no need to import libraries as Python has builtin syntax for this already. Rather than just printing, it returns a data structure like you asked for, and you get to join the strings together to boot:
combinations = [
p + " " + t + " " + s
for t in ts for p in prefix for s in suffix]
Post a Comment for "Find All Possible Combinations"