RE: Creating unique combinations from lists

2008-01-17 Thread Reedick, Andrew
-Original Message- From: [EMAIL PROTECTED] [mailto:python- [EMAIL PROTECTED] On Behalf Of Tim Chase Sent: Wednesday, January 16, 2008 3:40 PM To: breal Cc: python-list@python.org Subject: Re: Creating unique combinations from lists You can use a recursive generator: def

RE: Creating unique combinations from lists

2008-01-17 Thread Reedick, Andrew
-Original Message- From: Tim Chase [mailto:[EMAIL PROTECTED] Sent: Thursday, January 17, 2008 10:30 AM To: Reedick, Andrew Cc: breal; python-list@python.org; [EMAIL PROTECTED] Subject: Re: Creating unique combinations from lists Yick...a nice demo of the power of eval

Re: Creating unique combinations from lists

2008-01-17 Thread Tim Chase
You can use a recursive generator: def iterall(*iterables): if iterables: for head in iterables[0]: for remainder in iterall(*iterables[1:]): yield [head] + remainder else: yield [] for thing in iterall( ['big', 'medium',

Re: Creating unique combinations from lists

2008-01-17 Thread Steven D'Aprano
On Thu, 17 Jan 2008 10:44:51 -0600, Reedick, Andrew wrote: -Original Message- From: Tim Chase [mailto:[EMAIL PROTECTED] Sent: Thursday, January 17, 2008 10:30 AM To: Reedick, Andrew Cc: breal; python-list@python.org; [EMAIL PROTECTED] Subject: Re: Creating unique combinations from

Creating unique combinations from lists

2008-01-16 Thread breal
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',

RE: Creating unique combinations from lists

2008-01-16 Thread Reedick, Andrew
-Original Message- From: [EMAIL PROTECTED] [mailto:python- [EMAIL PROTECTED] On Behalf Of breal Sent: Wednesday, January 16, 2008 2:15 PM To: python-list@python.org Subject: Creating unique combinations from lists I have three lists... for instance a = ['big', 'small

Re: Creating unique combinations from lists

2008-01-16 Thread breal
On Jan 16, 11:33 am, Reedick, Andrew [EMAIL PROTECTED] wrote: -Original Message- From: [EMAIL PROTECTED] [mailto:python- [EMAIL PROTECTED] On Behalf Of breal Sent: Wednesday, January 16, 2008 2:15 PM To: [EMAIL PROTECTED] Subject: Creating unique combinations from lists I

Re: Creating unique combinations from lists

2008-01-16 Thread Martin v. Löwis
I could do nested for ... in loops, but was looking for a Pythonic way to do this. Ideas? I find nested for loops very Pythonic. Explicit is better than implicit, and simple is better than complex. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating unique combinations from lists

2008-01-16 Thread Tim Chase
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',

Re: Creating unique combinations from lists

2008-01-16 Thread Matimus
On Jan 16, 11:15 am, breal [EMAIL PROTECTED] wrote: 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']

Re: Creating unique combinations from lists

2008-01-16 Thread Steven D'Aprano
On Wed, 16 Jan 2008 11:15:16 -0800, breal wrote: I could do nested for ... in loops, but was looking for a Pythonic way to do this. Ideas? What makes you think nested loops aren't Pythonic? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating unique combinations from lists

2008-01-16 Thread Tim Chase
I could do nested for ... in loops, but was looking for a Pythonic way to do this. Ideas? What makes you think nested loops aren't Pythonic? On their own, nested loops aren't a bad thing. I suspect they become un-Pythonic when they make code look ugly and show a broken model of the

Re: Creating unique combinations from lists

2008-01-16 Thread [EMAIL PROTECTED]
for a in range(5): ... for z in range(5): means the inner loop runs 5**26 times so perhaps it's not only unpythonic but also uncomputable... -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating unique combinations from lists

2008-01-16 Thread Tim Chase
for a in range(5): ... for z in range(5): means the inner loop runs 5**26 times so perhaps it's not only unpythonic but also uncomputable... only if you're impatient ;) yes, it was a contrived pessimal example. It could be range(2) to generate boolean-number

Re: Creating unique combinations from lists

2008-01-16 Thread Martin v. Löwis
The main emphasis was to show that there was a pattern unfolding that should have been translated into more pythonic code than just hard-coding nested loops. Practicality beats purity. That you would solve a more general problem in a more general way doesn't mean that you shouldn't solve the