[portland] Clue Stick Needed

jason kirtland jek at discorporate.us
Thu Jan 17 01:01:07 CET 2008


Rich Shepard wrote:
>    I think that I'm making progress, but I'm still not there. Here's the
> relevant portion of the function:
> 
>  	proper = lambda t: (t[3],t[2], t[1], t[0], t[5])
>          sorted(self.appData.tsets, key=proper)
>  	for i in range(len(self.appData.tsets)):
>  		row = self.appData.tsets[i]
>  	        # select component, subcomponent, variable names
>          	curComp = row[3]
>  		curSub = row[2]
>  	        curVar = row[1]
>  	        tb.textOut(row[3])
>  	        tb.x += 9
>  	        if row[2] == '':
>  	        tb.x += 36
>  	        tb.textOut(curSub)
>  	        tb.x += 9
>  	        tb.textLine(curVar)
>  	        for i in range(7):
>  	        if i == row[16]:
>  			print curVar, row[0], row[5], row[4]
> 
>    This throws no errors, but the resulting list is still not in order:
> 
>  	FloodControl Poor 1 Left Shoulder
>  	FloodControl Average 2 Trapezoid
>  	AnimalRefugia Poor 1 Left Shoulder
>  	AnimalRefugia High 3 Right Shoulder
>  	FloodControl High 3 Right Shoulder
>  	AnimalRefugia Adequate 2 Trapezoid
> 
>    The third FloodControl should follow the second one. Is my syntax error
> obvious?

It's here:
 >  	proper = lambda t: (t[3],t[2], t[1], t[0], t[5])
 >          sorted(self.appData.tsets, key=proper)
 >  	for i in range(len(self.appData.tsets)):

sorted() is sorting a copy of the tsets and discarding the result.  Either:

    self.appData.tsets.sort(key=proper)

if tsets is a list and you don't mind modifying in-place, or, better:

    for i, row in enumerate(sorted(self.appData.tsets, key=proper)):
        # select component, subcomponent, variable names
        curComp = row[3]


More information about the Portland mailing list