Creating unique combinations from lists

Reedick, Andrew jr9445 at ATT.COM
Wed Jan 16 14:33:27 EST 2008



> -----Original Message-----
> From: python-list-bounces+jr9445=att.com at python.org [mailto:python-
> list-bounces+jr9445=att.com at python.org] On Behalf Of breal
> Sent: Wednesday, January 16, 2008 2:15 PM
> To: python-list at python.org
> Subject: Creating unique combinations from lists
> 
> I have three lists... for instance
> 
> a = ['big', 'small', 'medium'];
> b = ['old', 'new'];
> c = ['blue', 'green'];
> 
> I want to take those and end up with all of the combinations they
> create like the following lists
> ['big', 'old', 'blue']
> ['small', 'old', 'blue']
> ['medium', 'old', 'blue']
> ['big', 'old', 'green']
> ['small', 'old', 'green']
> ['medium', 'small', 'green']
> ['big', 'new', 'blue']
> ['small', 'new', 'blue']
> ['medium', 'new', 'blue']
> ['big', 'new', 'green']
> ['small', 'new', 'green']
> ['medium', 'new', 'green' ]
> 
> I could do nested for ... in loops, but was looking for a Pythonic way
> to do this.  Ideas?


http://www.python.org/dev/peps/pep-0202/




More information about the Python-list mailing list