There are a few problems here.
First, you can't index by floats because it doesn't make any sense.
Second, if you could, there is a problem with the way floats are interpreted/calculated (the reason why sometimes your results are like 3.99999999 instead of 4).
My recommendation is to index your values using a dictionary rounded to a certain number of decimals. This way you will ensure your data always matches!
Since you cannot map stuff by immutable keys, you need a tuple.
An example of how this would work:
mydict = {}
a = (41.797, 34.0)
object_a = 'A'
b = (42.152, 34.56)
object_b 'B'
mydict[round(a[0], 3), round(a[1], 3)] = object_a
mydict[round(b[0], 3), round(b[1], 3)] = object_b
print ( my_dict[round(a[0], 3), round(a[1], 3)] )
print ( my_dict[round(b[0], 3), round(b[1], 3)] )
>> 'A'
>> 'B'
If you want to update the object you simply use the rounded tuple
mydict[round(a[0], 3), round(a[1], 3)] = 'CHICKEN'
print ( my_dict[round(a[0], 3), round(a[1], 3)] )
print ( my_dict[round(b[0], 3), round(b[1], 3)] )
>> 'CHICKEN'
>> 'B'
If the code gets too messy, just add a function to round tuples:
def round_tuple(tupl, decimals=3):
return round(tupl[0], decimals), round(tupl[1], decimals)
This way you just do this:
target = round_tuple(tup)
mydict[target] = 'CHICKEN'
objects? Are they already created? Do you need to create them? Can you modify theseobjects?