How would you program this?

engsol engsolnorm at peak.org
Thu Mar 3 22:34:59 EST 2005


On Thu, 03 Mar 2005 19:32:19 -0700, Steven Bethard <steven.bethard at gmail.com> wrote:

>engsol wrote:
>> I don't fully understand this line of your code:
>> return [(a,b,c) for a in ns for b in ns for c in ns if a + b + c == limit]
>> If  the "if" part is true, does it  'trigger' the return?
>
>This code is basically equivalent to:
>
>lc = []
>for a in ns:
>     for b in ns:
>         for c in ns:
>             if a + b + c == limit:
>                 lc.append((a, b, c))
>return lc
>
>Does that help?
>
>STeVe

Now it's clear....thank you.
Norm B




More information about the Python-list mailing list