[Zope-dev] Re: [Zope] Sorting a list

Dieter Maurer dieter@handshake.de
Mon, 10 Jul 2000 20:44:14 +0200 (CEST)


RC Compaan writes:
 > I have a list:
 > mylist=[('R',31),('I',80),('A',80),('S',23),('E',35),('C',21)]
 > 
 > I want to rebuild the list sorted from high to low on the sequence-item.
 > 
 > When i call  <dtml-in mylist sort=sequence-item reverse> the list gets
 > sorted on the sequence-key not the sequence-item.  As I understand the
 > alphabetical characters are the sequence-keys and the float values are the
 > sequence-items.
 > 
 > Where do misunderstand?
What you see is caused by the following code in
"DocumentTemplate.DT_In.InClass.__init__":

        if has_key('sort'):
            self.sort=sort=args['sort']
            if sort=='sequence-item': self.sort=''


This means, "dtml-in sort=sequence-item" does not sort
by "sequence-item" but by the complete tuple (key,item).

I think, the special treatment of lists of pairs is
altogether a slight misfeature. It would probably
have been better to use a special "dict" attribute
in analogy to the "mapping" attribute to call
for the special pair interpretation.
'sequence-item' should then still be the complete item
and 'sequence-value' the second pair component.
Probably, it is too late by now to change this.


Dieter