Skip to content
Advertisement

check if numeric element is in an interval key dictionary in python

from the following dictionary with tuple as keys and a string as value:

JavaScript

by using the dict, how would be possible to use a function with the following behaviour?

JavaScript

gives the following output:

JavaScript

Advertisement

Answer

If you expect age to be within multiple intervals and you want to get them all:

JavaScript

I have added an overlapping interval to your data

JavaScript

If you want the first value only:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement