[SciPy-User] maping a float to a function value

Charles R Harris charlesr.harris at gmail.com
Wed Dec 9 16:13:49 EST 2009


On Wed, Dec 9, 2009 at 2:09 PM, nicky van foreest <vanforeest at gmail.com>wrote:

> Sorry, perhaps I was less clear than I thought. A new attempt... I
> want to store floats as keys in a dict. but this is not a smart idea.
> To show the problem:
>
> In [1]: a  = {}
>
> In [6]: import math
>
> In [9]: a[1/3.]  = 4
>
> In [10]: a[1./(math.sqrt(3)*math.sqrt(3))]
> ---------------------------------------------------------------------------
> KeyError                                  Traceback (most recent call last)
>
> /home/nicky/<ipython console> in <module>()
>
> KeyError: 0.33333333333333337
>
> What would be a smart way to use floats as keys in a dict, in such a
> way that the above problem does not occur?
>
>
The question is: why do you want to use floats as keys in a dictionary?

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20091209/beb917a9/attachment.html>


More information about the SciPy-User mailing list