我有一个带有浮点数作为键和对象作为值的字典。我收到一个浮点数,我想知道这个浮点数在两个键之间。我怎么找到这个?
我在代码中的意思示例:
a = {}
a[1.2] = some_unimportant_instance
a[2.3] = some_other_unimportant_instance
a[2.6] = some_third_unimportant_instance
etc...
r = 2.5
# a[r] will not work
# I want something that returns the two numbers around r
# in this case, 2.3 and 2.6.