[portland] Nested for loops, 4 levels deep

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


On Tue, 20 May 2008, Dylan Reinhardt wrote:

> If I understand correctly, you want the data to lay out something like this:
>
> Wildlife
>       Fish
>               Abundance
>                       WFA1         if abundance is few then...
>                       WFA2         if abundance is moderate then...
>                       WFA3         if abundance is many then...

Dylan,

   This is correct. The rule number/rule text pairs will be in a table, but
that's a formatting detail.

> Assuming that to be the case, what about:
>
> for v in varList:
>    if row[0] == v[2] and s[1] == v[3]:
>        ivr.write(v[0])
>        ivr.write('\n''\n')
>        subitems = [tuple(item[-2:]) for item in varList if item[:3] == v[:3]]
>        for item in subitems:
>           ivr.write('\t%s\t%s\n' % item)
>
> Untested, obviously... but maybe that's close enough to be useful?

   I understand the list comprehension, but my modifications don't help. The
multiple pairs at the lowest level are in appData.rules, not in v[]. I tried
several variants, the latest being:

subitems = [tuple(item[-2:]) for item in appData.rules if appData.rules[2] == v[0]]

followd by 'print subitems', but only empty lists are printed. This is the
conundrum that set me chasing my tail the past couple of days: how to
iterate through the rows of appData.rules[] to pull out the appropriate last
two items in each tuple where the first three items have been specified.

Rich


More information about the Portland mailing list