Skip to content
Advertisement

looping through dictionary and printing first value where condition is met

Having some trouble getting this simple conditional to work. I have a dictionary with 10 key-value pairs as follows:

JavaScript

I’m trying to loop through the dictionary and print the key for the first value that is below 0.05.

This is the code I have right now:

JavaScript

Can anyone help me see where I’m going wrong here?

Edit: It should be noted that I only want to print the first key where the condition is met and then end the loop.

Advertisement

Answer

This is what your looking for:

JavaScript
Advertisement