[EMAIL PROTECTED] wrote:
Thank you all so much for the generous dollop of help: the dictionary
suggestion is particularly helpful. The problem arises as follows: A
software application stores the securities held in a portfolio in a
.csv file, one row per security, with three colulmns.
The first has
Thank you all so much for the generous dollop of help: the dictionary
suggestion is particularly helpful. The problem arises as follows: A
software application stores the securities held in a portfolio in a
.csv file, one row per security, with three colulmns.
The first has a security identifier o
[EMAIL PROTECTED] wrote:
L=[['A', 100], ['B', 300], ['A', 400], ['B', -100]]
I want to aggregate these lists, i.e. to reduce L to
L=[['A', 500], ['B', 200]] #500 = 100+400, 200=300-100
"""
from itertools import groupby
from operator import itemgetter
[(key, sum(item[1] for item in sublist))
for ke
Well, I'm not sure if this is what you want, but you could use a
dictionary:
>>> d={}
>>> for i,e in L:
if d.has_key(i):
d[i] += e
else:
d[i] = e
>>> d
{'A': 500, 'B': 200}
>>>
--
http://mail.python.org/mailman/listinfo/python-lis
Paul Rubin wrote:
> [EMAIL PROTECTED] writes:
> > I have list of lists of the following form
> >
> > L=[['A', 100], ['B', 300], ['A', 400], ['B', -100]]
> >
> > I want to aggregate these lists, i.e. to reduce L to
> > L=[['A', 500], ['B', 200]] #500 = 100+400, 200=300-100
>
> How about:
>
> v
[EMAIL PROTECTED] writes:
> I have list of lists of the following form
>
> L=[['A', 100], ['B', 300], ['A', 400], ['B', -100]]
>
> I want to aggregate these lists, i.e. to reduce L to
> L=[['A', 500], ['B', 200]] #500 = 100+400, 200=300-100
How about:
v = {}
for name,val in L:
v[n