diff options
author | Raymond Hettinger <python@rcn.com> | 2005-03-09 16:38:48 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2005-03-09 16:38:48 (GMT) |
commit | 984f9bb7140683fa9b950b42a035477108aba88f (patch) | |
tree | 48777048a10360528f7da6e08a495dcc7e9ee3a8 /Doc/lib/liboperator.tex | |
parent | 6a3f4f7bc33d4701c2fff0d75f5ed184f5643229 (diff) | |
download | cpython-984f9bb7140683fa9b950b42a035477108aba88f.zip cpython-984f9bb7140683fa9b950b42a035477108aba88f.tar.gz cpython-984f9bb7140683fa9b950b42a035477108aba88f.tar.bz2 |
operator.itemgetter() and operator.attrgetter() now support extraction
of multiple fields. This provides direct support for sorting by
multiple keys.
Diffstat (limited to 'Doc/lib/liboperator.tex')
-rw-r--r-- | Doc/lib/liboperator.tex | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/Doc/lib/liboperator.tex b/Doc/lib/liboperator.tex index 52c0e93..d3c974a 100644 --- a/Doc/lib/liboperator.tex +++ b/Doc/lib/liboperator.tex @@ -306,24 +306,31 @@ as arguments for \function{map()}, \function{sorted()}, \method{itertools.groupby()}, or other functions that expect a function argument. -\begin{funcdesc}{attrgetter}{attr} +\begin{funcdesc}{attrgetter}{attr\optional{, args...}} Return a callable object that fetches \var{attr} from its operand. +If more than one attribute is requested, returns a tuple of attributes. After, \samp{f=attrgetter('name')}, the call \samp{f(b)} returns -\samp{b.name}. +\samp{b.name}. After, \samp{f=attrgetter('name', 'date')}, the call +\samp{f(b)} returns \samp{(b.name, b.date)}. \versionadded{2.4} +\versionchanged[Added support for multiple attributes]{2.5} \end{funcdesc} -\begin{funcdesc}{itemgetter}{item} +\begin{funcdesc}{itemgetter}{item\optional{, args...}} Return a callable object that fetches \var{item} from its operand. +If more than one item is requested, returns a tuple of items. After, \samp{f=itemgetter(2)}, the call \samp{f(b)} returns \samp{b[2]}. +After, \samp{f=itemgetter(2,5,3)}, the call \samp{f(b)} returns +\samp{(b[2], b[5], b[3])}. \versionadded{2.4} +\versionchanged[Added support for multiple item extraction]{2.5} \end{funcdesc} Examples: \begin{verbatim} ->>> from operator import * +>>> from operator import itemgetter >>> inventory = [('apple', 3), ('banana', 2), ('pear', 5), ('orange', 1)] >>> getcount = itemgetter(1) >>> map(getcount, inventory) |