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
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
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
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
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
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
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
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
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
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
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
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,
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 =
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
-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
-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
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',
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
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',
-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
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
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
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',
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']
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
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
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
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
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
29 matches
Mail list logo