Re: [Tutor] Python Cookbook
by Erik Price other posts by this author
Aug 26 2002 12:42PM messages near this date
Re: [Tutor] Python Cookbook
|
Re: [Tutor] Python Cookbook
On Monday, August 26, 2002, at 03:06 AM, Danny Yoo wrote:
> I think it's pretty good; have you had a chance to look at the sample
> Chapter 1 yet?
>
> http://www.oreilly.com/catalog/pythoncook/chapter/index.html
>
> As a warning: I'm not a disinterested party in my endorsement. *grin*
Well, in that first chapter, David Ascher's opening commentary includes
the following quote, that I need help with:
"""
My favorite recent language features are list comprehensions and the new
applicability of the * and ** tokens to function calls as well as to
function definitions. List comprehensions have clearly become wildly
successful, if the authors of this volume are representative of the
Python community at large, and have largely demoted the map and filter
built-in functions. Less powerful, but equally elegant, are * and **.
Since Python 2.0, the oft-quoted recipe:
def method(self, argument, *args, **kw):
# Do something with argument
apply(callable, args, kw)
can now be done much more elegantly as:
def method(self, argument, *args, **kw):
# Do something with argument
callable(*args, *kw)
"""
This must be a new form of callable(), because in my copy of Python
Essential Reference (for 2.1), callable() takes one parameter argument
that is an object.
I understood what map() and filter() do, but why are list comprehensions
better? FWIW, I don't really know exactly what a list comprehension is,
only that PER says that the following
map(function, alist)
can be better written using list comprehension as
[function(x) for x in alist]
-- why?
Thanks for any thoughts that anyone can contribute.
Erik
--
Erik Price
email: erikprice@[...].com
jabber: erikprice@[...].org
_______________________________________________
Tutor maillist - Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Erik Price
Danny Yoo
Erik Price
Yigal Duppen
Erik Price
Scot W. Stevenson
Yigal Duppen
|