[Python-checkins] python/dist/src/Doc/lib liboperator.tex, 1.32, 1.33

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Wed Mar 9 17:38:50 CET 2005


Update of /cvsroot/python/python/dist/src/Doc/lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1975/Doc/lib

Modified Files:
	liboperator.tex 
Log Message:
operator.itemgetter() and operator.attrgetter() now support extraction
of multiple fields.  This provides direct support for sorting by
multiple keys.



Index: liboperator.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/liboperator.tex,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- liboperator.tex	1 Jan 2005 00:28:37 -0000	1.32
+++ liboperator.tex	9 Mar 2005 16:38:48 -0000	1.33
@@ -306,24 +306,31 @@
 \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)



More information about the Python-checkins mailing list