Prev: how to copy and move file with its attribute?
Next: CPython 3.1.1 docs error in noddy3 example?
From: Stefan Behnel on 27 Jul 2010 07:16
geremy condra, 27.07.2010 12:54:
> On Wed, Jul 21, 2010 at 8:17 AM, John Nagle wrote:
>> On 7/19/2010 9:56 AM, dhruvbird wrote:
>>> On Jul 19, 9:12 pm, Brian Victor wrote:
>>>> dhruvbird wrote:
>>>> Having offered this, I don't recall ever seeing reduce used in real
>>>> python code, and explicit iteration is almost always preferred.
>>> Yes, even I have noticed that reduce is a tad under-used function.
>> Yes, I had a use case for it once, but it wasn't worth the trouble.
>> "map" is often useful, but "reduce", not so much.
>> Python isn't really a functional language. There's no bias toward
>> functional solutions, lambdas aren't very general, and the performance
>> isn't any better. Nor is any concurrency provided by "map" or "reduce".
>> So there's no win in trying to develop cute one-liners.
> Too bad about the lack of concurrency, would be many places where that
> would be nice.
Besides the many places where the current properties match just fine, there
are some places where concurrency would be helpful. So I wouldn't call it
"lack" of concurrency, as that seems to imply that it's a missing feature
in what both builtins are targeted to provide. Just use one of the
map-reduce frameworks that are out there if you need concurrency in one way
or another. Special needs are not what builtins are there for.
From: sturlamolden on 27 Jul 2010 09:51
On 19 Jul, 13:18, dhruvbird <dhruvb...(a)gmail.com> wrote:
> I have a list of integers: x = [ 0, 1, 2, 1, 1, 0, 0, 2, 3 ]
> And would like to compute the cumulative sum of all the integers
> from index zero into another array. So for the array above, I should
> get: [ 0, 1, 3, 4, 5, 5, 5, 7, 10 ]
> What is the best way (or pythonic way) to get this.
At least for large arrays, this is the kind of task where NumPy will
>>> import numpy as np
>>> np.cumsum([ 0, 1, 2, 1, 1, 0, 0, 2, 3 ])
array([ 0, 1, 3, 4, 5, 5, 5, 7, 10])
From: Aahz on 2 Aug 2010 13:29
In article <7xpqyjgvjm.fsf(a)ruckus.brouhaha.com>,
Paul Rubin <no.email(a)nospam.invalid> wrote:
>I think Peter Otten's solution involving a generator is the one most in
>the current Python spirit. It's cleaner (for my tastes) than the ones
>that use things like list.append.
Aahz (aahz(a)pythoncraft.com) <*> http://www.pythoncraft.com/
"....Normal is what cuts off your sixth finger and your tail..." --Siobhan