building a dict

vsoler vicente.soler at gmail.com
Sat Mar 13 22:42:12 CET 2010


On 13 mar, 18:16, ru... at yahoo.com wrote:
> On Mar 13, 9:26 am, ru... at yahoo.com wrote:> That should be:
> > d = {}
> > for item in m:
>
>       key = item[0];  value = item[1]
>
> >     if key is None or value is None: continue
> >     if key not in dict:
> >         d[key] = [1, value]
> >     else:
> >         d[key][0] += 1
> >         d[key][1] += value
>
> That's it.  Any other mistakes, you find 'em.

Thank you all. Your answers are more than valuable to me. I'll study
them carefully, but no doubt, my post has been answered.

By the way, I suppose I am the OP. Since I am not an native English
speaking person, I do not know what it stands for. Perhaps you can
tell me.

>From what I see from your posts, you would have preferred that I
included in my original post my "for loop", so that the post is not so
abstract. I have taken note and I'll make it better next time.

Thank you for your help.

Vicente Soler



More information about the Python-list mailing list