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

Posted by Baresi on Stack Overflow See other posts from Stack Overflow or by Baresi
Published on 2010-03-05T22:15:29Z Indexed on 2010/03/11 21:49 UTC
Read the original article Hit count: 392

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about python

Related posts about algorithm