title: Check for value if it exists in given ranges
body: <p>I have a CSV file as follows:</p>
  
  <pre><code>ratio,range
  g:k:l,1-500
  g:c:m,501-1000
  g:k:l,1001-1500
  </code></pre>
  
  <p>I have to check that a particular value exists in which of the ranges and then for given Y check whether it exists in the ratio. I have implemented in this way-</p>
  
  <pre><code>import csv , json
  import ast
  
  x=1600
  y='k'
  csvFilePath = "prorate - Sheet1.csv"
  arr = []
  #read the csv and add the arr to a array
  
  with open (csvFilePath) as csvFile:
      csvReader = csv.DictReader(csvFile)
      # print(csvReader)
      for csvRow in csvReader:
          arr.append(csvRow)
  arr= json.dumps(arr)
  arr = ast.literal_eval(arr)
  # print(arr)
  
  for lists in arr:
      if int(lists['range'].split('-')[0]) &lt;= x &lt;= int(lists['range'].split('-')[1]):
          if y in lists['ratio'].split(':'):
              print(" Found {0} in range {1} for y={2}".format(x,lists['range'], y))
          else:
              print(" Not found {0} and x={1}".format(y,x))
      else:
          print("Not found {0} in all the ranges with y={1}".format(x,y)) 
  </code></pre>
  
  <p>When the value is not in the given range then error thrown is multiple times when I only want it to be once.I tried using try,except and else but I am not able to get it through. Also is there any more efficient way to solve this?</p>