newbie dictionary question

James Chapman
Mon Apr 22 00:27:21 EDT 2002


Hi,

Thanks for the solution. I think it's better then what I wrote.

I think I'll also change the keys to intergers. While the bids come in as
floats they are constrained too be no more then three decimal places.

Thanks again,


"Raymond Hettinger" <python at rcn.com> wrote in message
news:a9vn1g$md7$1 at bob.news.rcn.net...
> "James Chapman ude.awoiu at nampahc-semaj>" <<reverse> > Hi,
> >
> I'm not sure if this counts as elegant, but it works:
> >>> [a.__setitem__(k, a.get(k,0)+v) for k,v in b.iteritems()]
> [None, None]
> >>> a
> {4.9699999999999998: 90, 4.9500000000000002: 200, 4.9900000000000002: 95,
> 4.96: 99}
>
> FWIW, I think using floats as a key is perilous.
>
>
> Raymond Hettinger
>
>





More information about the Python-list mailing list