Future of the Python Linux Distribution

Ben Wolfson rumjuggler at home.com
Sun May 7 19:31:31 EDT 2000


On Mon, 8 May 2000 00:55:37 +0200 (MET DST), Vetle Roeim
<vetler at ifi.uio.no> wrote:

>> map, lambda, apply, filter.  Obfuscation at your fingertips. :-) Using
>> {}.update(), I believe it's possible to write programs that use only
>> expressions; no statements.
>
>Yes, of course. But I have a feeling many people don't use these
>functions, unless they have taken a course on functional programming ;-)

map, filter and reduce are pretty easy to figure out without knowing
any functional programming, actually.  You just need to get
sufficiently bored with for loops.  The problem is that once you put
them in, your code's legibility decreases if they're combined with one
another.  I doubt I could parse this if I hadn't written it:

from operator import add,indexOf
list=open('ceci ne pas un playlist.m3u').readlines()
open('mp3s','w').write(reduce(add, map(lambda a: a[1+a.find(',':]\
                   filter(lambda e, l=list:indexOf(l,e)%2, list))))

and it's pretty simple.

>It's often very useful to use these functions, but they provide solutions
>not easily available in more popular programming languages, such as C and
>Java. I refrain from mentioning C++ in the previous sentance, because C++
>actually has those functions (except lambda), although many people don't
>know about them.

I know about for_each and copy_if, which are what I assume you mean as
analogues of map and filter, but what corresponds to apply?

-- 
Barnabas T. Rumjuggler

The world is turning into a cesspool of imbeciles.
 -- Harlan Ellison



More information about the Python-list mailing list