Float values as dictionary key

前端 未结 5 767
时光说笑
时光说笑 2020-11-27 21:30

I am developing a class for the analysis of microtiter plates. The samples are described in a separate file and the entries are used for an ordered dictionary. One of the ke

5条回答
  •  盖世英雄少女心
    2020-11-27 22:06

    Perhaps you want to truncate your float prior to using is as key?

    Maybe like this:

    a = 0.122334
    round(a, 4)       #<-- use this as your key?
    

    Your key is now:

    0.1223           # still a float, but you have control over its quality
    

    You can use it as follows:

    dictionary[round(a, 4)]   
    

    to retrieve your values

提交回复
热议问题