T
T
Timebird2016-12-31 07:56:01
Python
Timebird, 2016-12-31 07:56:01

How to find the index in the dictionary, having a float value?

Let there obj = {"abc": "37.6215879462381080"}
be Is it possible to find somehow by the value "37.6215879462381080" that it belongs to "abc"?
PS Happy New Year everyone! =)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Derevianko Alexander, 2016-12-31
@Timebird

you can and do not need to bypass anything - and it doesn’t matter if it is a string or something else. The main thing is that the key should be an immutable object.
For example, if you have two objects in the dictionary (or more - it doesn't matter), then the desired one is searched like this:
obj = {"abc" : "37.6215879462381080", "def" : "234.456"}
for (k, v) in obj.items ():
if k== 'abc': # or if v == "37.6215879462381080": print(k) if necessary
print(v)
response 37.6215879462381080
watch for indentation - they are not shown here.
Happy new year friends!

E
Evgeniy _, 2017-01-03
@GeneD88

obj.keys()[obj.values().index("37.6215879462381080")] == "abc"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question