Framework for a beginner

Alek Storm alek.storm at gmail.com
Thu Apr 19 07:20:04 EDT 2012


On Wed, Apr 18, 2012 at 11:21 PM, lkcl <luke.leighton at gmail.com> wrote:

> On Apr 11, 9:11 pm, biofob... at gmail.com wrote:
>
> > I am new to python and only have read the Byte of Python ebook, but want
> to move to the web. I am tired of being a CMS tweaker and after I tried
> python, ruby and php, the python language makes more sense (if that makes
> any "sense" for the real programmers).
>
>  yeah, it does :)  python is... the best word i can describe it is:
> it's beautiful.  it has an elegance of expression that is only marred
> by the rather silly mistake of not taking map, filter and reduce into
> the list object itself: l.map(str) for example would be intuitive,
> compact and elegant.  instead, i have to look up how to use map each
> and every damn time!  the reason for the mistake is historical: map,
> filter and reduce were contributed by a lisp programmer.  that lisp
> programmer, presumably, was used to everything being function(args...)
> and it simply didn't occur to anyone to properly integrate map, filter
> and reduce properly into the list objects that they work with.
>

Why not use list comprehension syntax? It gets you map and filter
functionality for free, and is more readable than python's clunky version
of lambdas. I believe they're faster than the for-loop equivalents, but I'm
not sure about the actual map() and filter() functions (reduce() was
removed from 3.0 for reasons I will never understand).

Map: [val+1 for val in some_list]
Filter: [val for val in some_list if val > 0]

Alek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120419/1587ba1e/attachment-0001.html>


More information about the Python-list mailing list