Re: Combinations of lists

2012-10-06 Thread Joshua Landau
On 4 October 2012 16:12, Steen Lysgaard boxeakast...@gmail.com wrote: 2012/10/4 Joshua Landau joshua.landau...@gmail.com: On 3 October 2012 21:15, Steen Lysgaard boxeakast...@gmail.com wrote: Hi, thanks for your interest. Sorry for not being completely clear, yes the length of m will

Re: Combinations of lists

2012-10-04 Thread Steen Lysgaard
2012/10/4 Joshua Landau joshua.landau...@gmail.com: On 3 October 2012 21:15, Steen Lysgaard boxeakast...@gmail.com wrote: Hi, thanks for your interest. Sorry for not being completely clear, yes the length of m will always be half of the length of h. (Please don't top post) I have a

Re: Combinations of lists

2012-10-04 Thread 88888 Dihedral
On Thursday, October 4, 2012 11:12:41 PM UTC+8, Steen Lysgaard wrote: 2012/10/4 Joshua Landau joshua.landau...@gmail.com: On 3 October 2012 21:15, Steen Lysgaard boxeakast...@gmail.com wrote: Hi, thanks for your interest. Sorry for not being completely clear, yes the

Combinations of lists

2012-10-03 Thread Steen Lysgaard
Hi, I am looking for a clever way to compute all combinations of two lists. Look at this example: h = ['A','A','B','B'] m = ['a','b'] the resulting combinations should be of the same length as h and each element in m can be used twice. The sought after result using h and m from above

Re: Combinations of lists

2012-10-03 Thread Alain Ketterlin
Steen Lysgaard boxeakast...@gmail.com writes: I am looking for a clever way to compute all combinations of two lists. Look at this example: h = ['A','A','B','B'] m = ['a','b'] the resulting combinations should be of the same length as h and each element in m can be used twice. The sought

Re: Combinations of lists

2012-10-03 Thread Steven D'Aprano
On Wed, 03 Oct 2012 16:26:43 +0200, Steen Lysgaard wrote: Hi, I am looking for a clever way to compute all combinations of two lists. Look at this example: h = ['A','A','B','B'] m = ['a','b'] the resulting combinations should be of the same length as h and each element in m can

Re: Combinations of lists

2012-10-03 Thread Manuel Pégourié-Gonnard
Steven D'Aprano scripsit : On Wed, 03 Oct 2012 16:26:43 +0200, Steen Lysgaard wrote: This is achieved by the code below, this however needs to go through all possible combinations (faculty of len(h)) and rule out duplicates as they occur and this is too much if for example len(h) is 16. I

Re: Combinations of lists

2012-10-03 Thread Joshua Landau
On 3 October 2012 15:26, Steen Lysgaard boxeakast...@gmail.com wrote: Hi, I am looking for a clever way to compute all combinations of two lists. Look at this example: h = ['A','A','B','B'] m = ['a','b'] the resulting combinations should be of the same length as h and each element in m

Re: Combinations of lists

2012-10-03 Thread Oscar Benjamin
On 3 October 2012 15:26, Steen Lysgaard boxeakast...@gmail.com wrote: Hi, I am looking for a clever way to compute all combinations of two lists. Look at this example: h = ['A','A','B','B'] m = ['a','b'] the resulting combinations should be of the same length as h and each element in m

Re: Combinations of lists

2012-10-03 Thread Joshua Landau
On 3 October 2012 20:20, Oscar Benjamin oscar.j.benja...@gmail.com wrote: On 3 October 2012 15:26, Steen Lysgaard boxeakast...@gmail.com wrote: Hi, I am looking for a clever way to compute all combinations of two lists. Look at this example: h = ['A','A','B','B'] m = ['a','b

Re: Combinations of lists

2012-10-03 Thread Steen Lysgaard
Lysgaard boxeakast...@gmail.com wrote: Hi, I am looking for a clever way to compute all combinations of two lists. Look at this example: h = ['A','A','B','B'] m = ['a','b'] the resulting combinations should be of the same length as h and each element in m can be used twice

Re: Combinations of lists

2012-10-03 Thread Oscar Benjamin
Oscar wrote: def uniquecombinations(h, m): for ha in submultisets(h, len(h)//2): hb = list(h) for c in ha: hb.remove(c) yield [m[0] + a for a in ha] + [m[1] + b for b in hb] h = ['A', 'A', 'B', 'B'] m = ['a', 'b'] for x in uniquecombinations(h,

Re: Combinations of lists

2012-10-03 Thread 88888 Dihedral
Oscar Benjamin於 2012年10月4日星期四UTC+8上午4時29分51秒寫道: Oscar wrote: def uniquecombinations(h, m): for ha in submultisets(h, len(h)//2): hb = list(h) for c in ha: hb.remove(c) yield [m[0] + a for a in ha] + [m[1] + b for b in hb] h =

Re: Combinations of lists

2012-10-03 Thread Joshua Landau
On 3 October 2012 21:15, Steen Lysgaard boxeakast...@gmail.com wrote: Hi, thanks for your interest. Sorry for not being completely clear, yes the length of m will always be half of the length of h. (Please don't top post http://www.catb.org/jargon/html/T/top-post.html) I have a solution to

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