Find value within a range in lookup table
- by francis
I have the simplest problem to implement, but so far I have not been able to get my head around a solution in Python.
I have built a table that looks similar to this one:
501 - ASIA
1262 - EUROPE
3389 - LATAM
5409 - US
I will test a certain value to see if it falls within these ranges, 389 -> ASIA, 1300 -> LATAM, 5400 -> US. A value greater than 5409 should not return a lookup value.
I normally have a one to one match, and would implement a dictionary for the lookup.
But in this case I have to consider these ranges, and I am not seeing my way out of the problem.
Maybe without providing the whole solution, could you provide some comments that would help me look in the right direction?
It is very similar to a vlookup in a spreadsheet.
I would describe my Python knowledge as somewhere in between basic to intermediate.
Many thanks in advance.