In article <7xpqyjgvjm@ruckus.brouhaha.com>,
Paul Rubin 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.
Agreed
--
Aahz (a...@pythoncraft.com)
On 19 Jul, 13:18, dhruvbird wrote:
> Hello,
> 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
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 a
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 pre
On Jul 21, 8:17 pm, 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.
>
> > Ye
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 funct
Peter Otten wrote:
dhruvbird 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 (
Brian Victor writes:
> def running_sum(result, current_value):
> return result + [result[-1]+current_value if result else current_value]
>
> reduce(running_sum, x, [])
That is not really any good because Python lists are actually vectors,
so result+[...] actually copies the whole old list, ma
dhruvbird wrote:
> On Jul 19, 4:28 pm, Peter Otten <__pete...@web.de> wrote:
>> dhruvbird 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 ab
On Jul 19, 4:28 pm, Peter Otten <__pete...@web.de> wrote:
> dhruvbird 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: [
On Jul 19, 9:12 pm, Brian Victor wrote:
> dhruvbird wrote:
> > Hello,
> > 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,
dhruvbird wrote:
> Hello,
> 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 p
On Mon, 19 Jul 2010 04:18:48 -0700, dhruvbird wrote:
> Hello,
> 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
On 07/19/2010 01:18 PM, dhruvbird wrote:
> Hello,
> 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 ]
> Wh
Am 19.07.2010 13:18, dhruvbird wrote:
> Hello,
> 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
2010/7/19 dhruvbird :
> Hello,
> 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
dhruvbird 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
Hi,
you may want to do like this
array=[0,1,2]
sumArray = []
for element in range(0,len(array)):
if element == 0 :
sumArray.append(array[element])
else:
sumArray.append((array[element] + sumArray[element-1]))
and then you can recheck it
Thanks,
nitin
On Mon, Jul 19, 20
18 matches
Mail list logo