Changeset 2426:88f739ebefc3 in livinglogic.python.xist

Show
Ignore:
Timestamp:
06/30/05 16:53:21 (15 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Give the sorted() method the same arguments as list.sort() and sorted()
in Python 2.4.

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • NEWS.xml

    r2420 r2426  
    1010 
    1111<item>Line number information is now added when parsing &html;.</item> 
     12 
     13<item>The <method>sorted</method> now supports the same arguments 
     14as <method>list.sort</method> and <function>sorted</function> in Python 2.4.</item> 
    1215 
    1316<item>Fixed a bug with element/attribute names that contained a <lit>.</lit> 
  • _xist/xsc.py

    r2418 r2426  
    16641664        return node 
    16651665 
    1666     def sorted(self, compare=lambda node1, node2: cmp(unicode(node1), unicode(node2))): 
    1667         """ 
    1668         <par>Return a sorted version of the <self/>. <arg>compare</arg> is 
    1669         a comparison function returning -1, 0, 1 respectively and defaults to comparing the 
    1670         <pyref class="Node" method="__unicode__"><class>__unicode__</class></pyref> value.</par> 
    1671         """ 
    1672         node = list(self) 
    1673         node.sort(compare) 
    1674         return self.__class__(node) 
     1666    def sorted(self, cmp=None, key=None, reverse=False): 
     1667        """ 
     1668        <par>Return a sorted version of the <self/>. <arg>cmp</arg>, <arg>key</arg> 
     1669        and <arg>reverse</arg> have to same meaning as for the builtin function 
     1670        <function>sorted</function>. 
     1671        """ 
     1672        return self.__class__(sorted(self, cmp, key, reverse)) 
    16751673 
    16761674    def reversed(self):