How would you program this?

Steven Bethard steven.bethard at
Fri Mar 4 03:32:19 CET 2005

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?


More information about the Python-list mailing list