[portland] Nested for loops, 4 levels deep
Dylan Reinhardt
python at dylanreinhardt.com
Wed May 21 01:13:04 CEST 2008
Could you paste in a small sample of the tuples you're using?
Maybe enough data to render 5 through 5.2.1 would do it...
Dylan
On Tue, May 20, 2008 at 3:40 PM, Rich Shepard <rshepard at appl-ecosys.com> wrote:
> I have been trying since yesterday morning to figure out how to nest for
> loops four levels deep. I've tried the suggestions offered by you folks as
> solutions to my previous needs in working with lists of tuples. This time
> I've had no problems getting three deep, but I cannot successfully (and
> properly) extract the last level. I'm confident that you'll show me several
> different ways of getting the desired result.
>
> I start with a list of tuples called appData.rules. Each tuple consists of
> 5 strings; we can refer to them as 'c,' 's,' 'v,' 'n,' and 't.' What I need
> is to print the hierarchies. That is, for each 'c' print all the 's'
> associated with it; for each 's' print each of its associated 'v'; for each
> 'v' print its associated 'n' and 't' in a two-column table
>
> Earlier in the module I define three lists of tuples: compList, subList,
> and varList. I use these to print the hierarchies of the first three items
> in each tuple.
>
> Here's the working code:
>
> proper = lambda t: (t[0], t[1], t[2], t[3])
>
> ivr.write('\\section{Rules}')
>
> appData.rules.sort(key=proper)
>
> for c in compList:
> curComp = None
> for row in appData.rules:
> if row[0] == c[1] and row[0] != curComp:
> ivr.write('\\subsection{%s}' % c[1])
> ivr.write('\n''\n')
> for s in subList:
> if row[0] == s[0]:
> ivr.write('\\subsubsection{%s}' % s[1])
> ivr.write('\n''\n')
> for v in varList:
> if row[0] == v[2] and s[1] == v[3]:
> ivr.write(v[0])
> ivr.write('\n''\n')
> """
> in here is where I want to create a table for rows 3
> and 4, where they belong to the specific c, s, and v
> """
> curComp = row[0]
>
> A page of the output is attached.
>
> I can get only 1 n/t pair printing for each c/s/v combination, or I have
> all n/t pairs repeating. I probably need another for loop, but those I've
> tried failed miserably.
>
> Rich
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: inputVars.pdf
> Type: application/pdf
> Size: 13528 bytes
> Desc: URL:
> <http://mail.python.org/pipermail/portland/attachments/20080520/3092c792/attachment.pdf>
> _______________________________________________
> Portland mailing list
> Portland at python.org
> http://mail.python.org/mailman/listinfo/portland
>
More information about the Portland
mailing list