def _shorten(code_list):
  """
  Shortens a list of numeric nomis geo codes into a string format where contiguous values are represented as ranges, e.g.
  1,2,3,6,7,8,9,10 -> "1...3,6,7...10"
  which can drastically reduce the length of the query url
  """
  # empty evals to False
  if not code_list:
    return ""
  if len(code_list) == 1:
    return str(code_list[0])

  code_list.sort() # assume this is a modifying operation
  short_string = ""
  index0 = 0
  index1 = 0 # appease lint
  for index1 in range(1, len(code_list)):
    if code_list[index1] != (code_list[index1-1] + 1):
      if index0 == index1:
        short_string += str(code_list[index0]) + ","
      else:
        short_string += str(code_list[index0]) + "..." + str(code_list[index1-1]) + ","
      index0 = index1
  if index0 == index1:
    short_string += str(code_list[index0])
  else:
    short_string += str(code_list[index0]) + "..." + str(code_list[index1])
  return short_string