-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
15 matches
Mail list logo