search - Finding a Value within a Range in a List of Tuple Values in Python -


I am trying to get the body mass index (BMI) classification for BMI value which comes within the standard BMI range -

I made the list of topleps of values ​​(see below), although I am open to any other data structure would be easy to do this between SQL, but I want to do it in pure Python, mostly because This means that as a practice in doing a low DB connection but more in "pure" Python.

  bmi_ranges = [] bmi_ranges.append ((u'Underweight ', u'svevere thinness', 0, 15.99)) bmi_ranges.append ((u'Underweight ', u'Moderate Thinness' , 16.00, 16.99)) bmi_ranges .append (('u'ndreit', you'mmed thines', 17.00, 18.49)) BMI.Care.Epand (('Normal Range', U 'Normal Border', 18.50, 24.99)) BMI_Range.Append ((U overweight ', U' overweight ', 25.00, 2 9. 9)) BMI_rangs.epend ((' o'bose ',' obese class i ', 30.00, 34.99) BMI_range.append ( ('O'bose', 'obese class II', 35.00, 39.99)) bmi_ranges.append ((u'Obese ', u'bbc class III', 40.00, 1000.00))  

If a limit is ok It's easy to walk with a list comp in the list of Tulips, but how do I know that the price is within the range of any other value?

  # BMI =  if , then the BMI_Range for BMI_Range in the BMI_Range [section to list the concepts that filter the items included in the results. 

Note: You have a non-inclusive upper limit (i.e. [A, B] + [B, C) + [C, D] at setter), and then conditional to a & lt ; = B & lt; C , there is no problem in the case of your side like this.


Comments