2 ms·
Each to his/her own. This isn't intended to be a language war. If you prefer map and reduce then you can have them: >>> from math import pi >>> add = flo
by RiderOfGiraffes 17y ago
Each to his/her own. This isn't intended to be a language war. If you prefer map and reduce then you can have them:
>>> from math import pi
>>> add = float.__add__
>>> def f(x): return (pi*x)**(-2)
>>> 1/reduce(add, map(f,range(1,1000)) )
6.0036796863530508
Or, as a one-liner:
>>> 1/reduce(float.__add__, map(lambda x:1.0/(3.1416*x)**2,range(1,1000)) )
People who aren't mathmos often find the list comprehensions more comprehensible, hence the version I wrote not as a competitor, but as an alternative, to yours.
Horses for courses. Personally, I've found the Python version to look more like math when I choose to express it like math, but I'm programming, so why not make it look like what I'm doing? Golf is a stupid game in programming. Understandability is the goal, but different readers find different things natural.
That's never going to go away.
- antirez 17y agoI guess it's really a matter of tastes indeed. My point is that, no matter the fact that I can try to mimic the Python idiomatic way or the reverse, there is a real difference between this languages, and is a difference that I see in many other languages, splitting them into two families: the "tools" languages that try to provide already build abstractions able to solve common problems, and the "concepts" languages where there are just a few rules you can combine to solve problems. I love the latter approach.