Most efficent way to create all possible combinations of four lists in Python?

algorithm, python

Solution

Is this what you're looking for? http://docs.python.org/library/itertools.html#itertools.product

Problem

I have four different lists. `headers`, `descriptions`, `short_descriptions` and `misc`. I want to combine these into all the possible ways to print out: ``` header\n description\n short_description\n misc ``` like if i had (i'm skipping short_description and misc in this example for obvious reasons) ``` headers = ['Hello there', 'Hi there!'] description = ['I like pie', 'Ho ho ho'] ... ``` I want it to print out like: ``` Hello there I like pie ... Hello there Ho ho ho ... Hi there! I like pie ... Hi there! Ho ho ho ... ``` What would you say is the best/cleanest/most efficent way to do this? Is `for`-nesting the only way to go?

Original source