Future of the Python Linux Distribution

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


* Ben Wolfson
> 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?

well.. maybe I was a little to quick. I don't think there exists an
'apply' in C++.. hmmm..

yes, it was for_each and copy_if i was thinking about. for more
algorithms, see chapter 5 of SGI's Standard Template Library
Programmer's Guide[0].


vr
[0]: http://www.sgi.com/Technology/STL/



More information about the Python-list mailing list