In article <[EMAIL PROTECTED]>,
"Gal Diskin" <[EMAIL PROTECTED]> wrote:
> Hi,
> I am writing a code that needs to iterate over 3 lists at the same
> time, i.e something like this:
>
> for x1 in l1:
> for x2 in l2:
> for x3 in l3:
> print "do something with", x1, x2, x3
>
"Gal Diskin" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
>
> On Dec 13, 3:47 pm, "Gal Diskin" <[EMAIL PROTECTED]> wrote:
> > Hi,
> > I am writing a code that needs to iterate over 3 lists at the same
> > time, i.e something like this:
> >
> > for x1 in l1:
> > for x2 in l2:
>
On Dec 13, 3:47 pm, "Gal Diskin" <[EMAIL PROTECTED]> wrote:
> Hi,
> I am writing a code that needs to iterate over 3 lists at the same
> time, i.e something like this:
>
> for x1 in l1:
> for x2 in l2:
> for x3 in l3:
> print "do something with", x1, x2, x3
>
> What I need
Is this suppose to be a brain teaser or something?
Michael Spencer wrote:
> John Henry wrote:
> > Carl Banks wrote:
> >
> >> The function can be extended to allow arbitrary arguments. Here's a
> >> non-minmal recursive version.
> >>
> >> def cartesian_product(*args):
> >> if len(args) > 1:
>
John Henry wrote:
> Carl Banks wrote:
>
>> The function can be extended to allow arbitrary arguments. Here's a
>> non-minmal recursive version.
>>
>> def cartesian_product(*args):
>> if len(args) > 1:
>> for item in args[0]:
>> for rest in cartesian_product(*args[1:]):
>>
Carl Banks wrote:
>
> The function can be extended to allow arbitrary arguments. Here's a
> non-minmal recursive version.
>
> def cartesian_product(*args):
> if len(args) > 1:
> for item in args[0]:
> for rest in cartesian_product(*args[1:]):
> yield (item
* at ([EMAIL PROTECTED]) wrote:
> Sorry for breaking into this thread, but I agree completely that any
> unnecessary indentations should be avoided. For the same reason I advocate
> that the following syntax should work:
>
> for x in some_list if some_condition:
> ... code
Sorry for breaking into this thread, but I agree completely that any
unnecessary indentations should be avoided. For the same reason I advocate
that the following syntax should work:
for x in some_list if some_condition:
... code ...
in stead of
for x in some_lis
Gal Diskin wrote:
> On Dec 13, 3:58 pm, Roberto Bonvallet <[EMAIL PROTECTED]>
> wrote:
> > Gal Diskin wrote:
> > > Hi,
> > > I am writing a code that needs to iterate over 3 lists at the same
> > > time, i.e something like this:
> >
> > > for x1 in l1:
> > >for x2 in l2:
> > >for x3 in
Hi,
if you "needs to iterate over 3 lists at the same" and according your example
> for (x1,x2,x3) in (l1,l2,l3):
> print "do something with", x1, x2, x3
i has guessed that you need this (may be i was wrong):
a = (1,2,3, 1)
b = (4,5,6)
c = (7,8,9, 2, 3)
for x, y, z in zip(a, b, c):
Thanks, that's an improvment (your first way).
But I still wish I could find an even shorter (or more elegent) way of
doing it. (Well, I guess if I expect every wish I have to come true I
should at least wish for something more valuable.)
Thanks again,
Gal
On Dec 13, 3:58 pm, "Fredrik Lundh" <[EM
Gal Diskin schrieb:
> Hi,
> I am writing a code that needs to iterate over 3 lists at the same
> time, i.e something like this:
>
> for x1 in l1:
> for x2 in l2:
> for x3 in l3:
> print "do something with", x1, x2, x3
>
> What I need to do is go over all n-tuples where the
Nothing seriously wrong, but it's not too elegent. Especially when the
number of lists you want to iterate over gets bigger (especially
because of the indentation in python). As you noticed (an phrased
better than me), what I was wondering is if there is a way to iterate
over the cartesian product,
Gal Diskin wrote:
> I am writing a code that needs to iterate over 3 lists at the same
> time, i.e something like this:
> for x1 in l1:
> for x2 in l2:
> for x3 in l3:
> print "do something with", x1, x2, x3
> I was wondering if one could write this more easily in some ma
"Gal Diskin" <[EMAIL PROTECTED]> writes:
> I am writing a code that needs to iterate over 3 lists at the same
> time, i.e something like this:
>
> for x1 in l1:
> for x2 in l2:
> for x3 in l3:
> print "do something with", x1, x2, x3
This does look a little kludgy (unteste
Gal Diskin wrote:
> Hi,
> I am writing a code that needs to iterate over 3 lists at the same
> time, i.e something like this:
>
> for x1 in l1:
>for x2 in l2:
>for x3 in l3:
>print "do something with", x1, x2, x3
What's wrong with this?
[...]
> I'd be very happy to receiv
"Gal Diskin" wrote:
> I am writing a code that needs to iterate over 3 lists at the same
> time, i.e something like this:
>
> for x1 in l1:
>for x2 in l2:
>for x3 in l3:
>print "do something with", x1, x2, x3
>
> What I need to do is go over all n-tuples where the first arg
Hi,
I am writing a code that needs to iterate over 3 lists at the same
time, i.e something like this:
for x1 in l1:
for x2 in l2:
for x3 in l3:
print "do something with", x1, x2, x3
What I need to do is go over all n-tuples where the first argument is
from the first list,
18 matches
Mail list logo