Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Doc/library/functools.rst

    r2 r391  
    1 :mod:`functools` --- Higher order functions and operations on callable objects
     1:mod:`functools` --- Higher-order functions and operations on callable objects
    22==============================================================================
    33
    44.. module:: functools
    5    :synopsis: Higher order functions and operations on callable objects.
     5   :synopsis: Higher-order functions and operations on callable objects.
    66.. moduleauthor:: Peter Harris <scav@blueyonder.co.uk>
    77.. moduleauthor:: Raymond Hettinger <python@rcn.com>
     
    99.. sectionauthor:: Peter Harris <scav@blueyonder.co.uk>
    1010
     11.. versionadded:: 2.5
    1112
    12 .. versionadded:: 2.5
     13**Source code:** :source:`Lib/functools.py`
     14
     15--------------
    1316
    1417The :mod:`functools` module is for higher-order functions: functions that act on
     
    1821The :mod:`functools` module defines the following functions:
    1922
     23..  function:: cmp_to_key(func)
     24
     25   Transform an old-style comparison function to a key function.  Used with
     26   tools that accept key functions (such as :func:`sorted`, :func:`min`,
     27   :func:`max`, :func:`heapq.nlargest`, :func:`heapq.nsmallest`,
     28   :func:`itertools.groupby`).  This function is primarily used as a transition
     29   tool for programs being converted to Python 3 where comparison functions are
     30   no longer supported.
     31
     32   A comparison function is any callable that accept two arguments, compares them,
     33   and returns a negative number for less-than, zero for equality, or a positive
     34   number for greater-than.  A key function is a callable that accepts one
     35   argument and returns another value that indicates the position in the desired
     36   collation sequence.
     37
     38   Example::
     39
     40       sorted(iterable, key=cmp_to_key(locale.strcoll))  # locale-aware sort order
     41
     42   .. versionadded:: 2.7
     43
     44.. function:: total_ordering(cls)
     45
     46   Given a class defining one or more rich comparison ordering methods, this
     47   class decorator supplies the rest.  This simplifies the effort involved
     48   in specifying all of the possible rich comparison operations:
     49
     50   The class must define one of :meth:`__lt__`, :meth:`__le__`,
     51   :meth:`__gt__`, or :meth:`__ge__`.
     52   In addition, the class should supply an :meth:`__eq__` method.
     53
     54   For example::
     55
     56       @total_ordering
     57       class Student:
     58           def __eq__(self, other):
     59               return ((self.lastname.lower(), self.firstname.lower()) ==
     60                       (other.lastname.lower(), other.firstname.lower()))
     61           def __lt__(self, other):
     62               return ((self.lastname.lower(), self.firstname.lower()) <
     63                       (other.lastname.lower(), other.firstname.lower()))
     64
     65   .. versionadded:: 2.7
    2066
    2167.. function:: reduce(function, iterable[, initializer])
Note: See TracChangeset for help on using the changeset viewer.