[Zope-dev] Confused about manipulating nested lists in DTML

skip@mojam.com (Skip Montanaro) skip@mojam.com (Skip Montanaro)
Mon, 15 Mar 1999 08:33:31 -0500


I have a list of lists:

    [['Washington', 'state'], ['Washington', 'state', 'Auburn'], ...]

The first element has length two, the rest length three.  If I pass that to
a DocumentTemplate instance as a parameter named "data" and manipulate it
thus:

    <!--#var "len(_['data'])"-->
    <!--#var data-->
    <!--#in data-->
	<!--#var "len(_['sequence-item'])"--> <!--#var sequence-item-->
	<!--#if "len(_['sequence-item']) == 2"-->
	    <p><!--#var "_['sequence-item'][0]"-->
	    <!--#in sequence-item-->
		<!--#var sequence-item--><br>
	    <!--#/in-->
	<!--#/if-->
    <!--#/in-->

I get the following output:

    9
    [['Washington', 'state'], ['Washington', 'state', 'Auburn'], ['Washington', 'state', 'Bainbridge Island'], ['Washington', 'state', 'Bellevue'], ['Washington', 'state', 'Bellingham'], ['Washington', 'state', 'Bremerton'], ['Washington', 'state', 'Chehalis'], ['Washington', 'state', 'Chimacum'], ['Washington', 'state', 'Cosmopolis'], ['Washington', 'state', 'Cowlitz County'], ['Washington', 'state', 'Ellensburg'], ['Washington', 'state', 'Elma'], ['Washington', 'state', 'Everett'], ['Washington', 'state', 'Friday Harbor'], ['Washington', 'state', 'George'], ['Washington', 'state', 'Gig Harbor'], ['Washington', 'state', 'Kennewick'], ['Washington', 'state', 'Kent'], ['Washington', 'state', 'Kirkland'], ['Washington', 'state', 'Lacey'], ['Washington', 'state', 'Lake Stevens'], ['Washington', 'state', 'Long Beach'], ['Washington', 'state', 'Longview'], ['Washington', 'state', 'Moses Lake'], ['Washington', 'state', 'Mount Vernon'], ['Washington', 'state', 'Oak Harbor'], ['Washin!
gton', 'state', 'Ocean Shores'], ['Washington', 'state', 'Olympia'], ['Washington', 'state', 'Packwood'], ['Washington', 'state', 'Pasco'], ['Washington', 'state', 'Phila/fort'], ['Washington', 'state', 'Port Angeles'], ['Washington', 'state', 'Port Townsend'], ['Washington', 'state', 'Pullman'], ['Washington', 'state', 'Puyallup'], ['Washington', 'state', 'Redmond'], ['Washington', 'state', 'Renton'], ['Washington', 'state', 'Richland'], ['Washington', 'state', 'Seattle'], ['Washington', 'state', 'Snoqualmie'], ['Washington', 'state', 'Spokane'], ['Washington', 'state', 'Stevenson'], ['Washington', 'state', 'Sunnyside'], ['Washington', 'state', 'Tacoma'], ['Washington', 'state', 'Twisp'], ['Washington', 'state', 'Vancouver'], ['Washington', 'state', 'Walla Walla'], ['Washington', 'state', 'Waterville'], ['Washington', 'state', 'Wenatchee'], ['Washington', 'state', 'Winthrop'], ['Washington', 'state', 'Woodinville'], ['Washington', 'state', 'Yakima']]
	18 ['Washington', 'state']
	    18 ['Washington', 'state', 'Auburn']
	    18 ['Washington', 'state', 'Bainbridge Island']
	    18 ['Washington', 'state', 'Bellevue']
	    18 ['Washington', 'state', 'Bellingham']
	    18 ['Washington', 'state', 'Bremerton']
	    18 ['Washington', 'state', 'Chehalis']
	    18 ['Washington', 'state', 'Chimacum']
	    18 ['Washington', 'state', 'Cosmopolis']
	    18 ['Washington', 'state', 'Cowlitz County']
	    ...

*What* objects have lengths of 9 and 18?  The outer list is length 33.  The
inner lists are all length 2 or 3.  Obviously I screwed up and misused
len(), but how?

Thx,

Skip Montanaro	| Mojam: "Uniting the World of Music" http://www.mojam.com/
skip@mojam.com  | Musi-Cal: http://www.musi-cal.com/
518-372-5583