Float values as dictionary key

前端 未结 5 748
时光说笑
时光说笑 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:18

    Another quick option is to use strings of the float

    a = 200.01234567890123456789
    b = {str(a): 1}
    for key in b:
        print(float(key), b[key])
    

    would print out

    (200.012345679, 1)
    

    notice a gets truncated at tenth digit after decimal point.

提交回复
热议问题