Favorite non-python language trick?

Mandus mandus at gmail.com
Sat Jun 25 15:19:44 EDT 2005


Sun, 26 Jun 2005 04:36:51 +1000 skrev Steven D'Aprano:
> On Sat, 25 Jun 2005 17:41:58 +0200, Konstantin Veretennicov wrote:
>
>> On 6/25/05, Mandus <mandus at gmail.com> wrote:
>>> It is really a consensus on this; that
>>> removing map, filter, reduce is a good thing? It will render a whole lot
>>> of my software unusable :(
>> 
>> I think you'll be able to use "from __past__ import map, filter,
>> reduce" or something like that :) They don't have to be built-in.
>
> More likely they will be moved to something like itertools than "__past__".
>
> Or just define them yourself:
>
> def map(f, seq):
>         return [f(x) for x in seq]
>
> def filter(p, seq):
>     return [x for x in seq if p(x)]
>
> def reduce(f, seq, zero):
>     r = zero
>     for x in seq: r = f(r, x)
>     return r

sure - that will be possible. But the main point (for me) is to avoid
the horrible slow for-loop in python (reduce...). By using the builtin reduce, I
move the for-loop into the c-code which performs better. 

map and filter with list-comprehensions is probably ok - I use
list-comprehensions a lot, but somehow like the syntax of map/filter
better.

When it comes to lambdas, I am not so sure. I use them all the time, and
I will certainly miss them, and I have used lambdas in ways which at
least take som tinkering to translate to normal def's (or rather
closures). But I am not sure yet whether I have cases which are
impossible to translate (hey, nothing is impossible, some things just
take a bit more time).

Oh, and by the way, I use python to solve PDEs :)

But as someone else said, this will take some time. And I can always put
the c-function back in my self when that time comes.

Another important point, which it seems Guido does not fancy very much,
is that Python can be an ok functional style language for those who like
it. I very much enjoy the concept of using different programming styles
within the same language. It is mostly a convenience - I admit that -
but it makes me more productive. I'll be very sorry if we take that away
from python.

Maybe I am to late to change Guido on this - but if we are many, maybe
we can!

-- 
Mandus - the only mandus around.



More information about the Python-list mailing list