Future of the Python Linux Distribution

Vetle Roeim vetler at news.ifi.uio.no
Sun May 7 19:55:46 EDT 2000


* Ben Wolfson
[snip]
> >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.

yes, they are simple. but most people don't know about them until
someone shows them how easy it can be.
 
> >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?

well.. perhaps I was a bit too quick. I don't think there is something
like apply. but I'm really not a C++ expert..


vr



More information about the Python-list mailing list