[portland] Nested for loops, 4 levels deep

Rich Shepard rshepard at appl-ecosys.com
Wed May 21 16:42:02 CEST 2008

On Wed, 21 May 2008, Dylan Reinhardt wrote:

> You're interested in all the n's and t's that share the same c, s, and
> v.   How about this:
> subitems = [tuple(item[-2:]) for item in appData.rules if item[:3] ==
> (c[1], s[1], v[0])]

   Perfect! Slicing item and matching to a tuple is an approach I've not seen

> I'm not sure I extracted c, s, and v correctly... I'm getting a little
> lost in there.  But the data you want consists of all the rows in
> appData.rules where the first three elements match c, s, and v.  This
> might not be the *exact* thing you're looking for, but should provide the
> correct answer once the correct comparison is made.

   You hit it dead on, Dylan. What I did not do in my list comprehension
attempts was to cast the result to a tuple. This has been a powerful
lesson. Thank you very much.


More information about the Portland mailing list