code: def _choose_different_host(old_ip, ip_list, failed_ips, questionable_ips):
      
      if not ip_list:
          # We don't have any hosts to choose from.
          return None
  
      ip_set           = set(ip_list)
      failed_set       = set(failed_ips)
      # Consider only those questionable IPs that aren't also failed and make
      # sure all of the ones in the questionable list are at least also present
      # in the overall IP list.
      questionable_set = set(questionable_ips).intersection(ip_set). \
                                               difference(failed_set)
  
      # Get all healthy IPs that are neither failed, nor questionable
      healthy_ips = list(ip_set.difference(failed_set, questionable_set))
  
      if healthy_ips:
          # Return one of the completely healthy IPs
          return random.choice(healthy_ips)
  
      if questionable_set:
          # Don't have any completely healthy ones, so return one of the
          # questionable ones. Not perfect, but at least may still provide
          # routing functionality for some time.
          if old_ip not in questionable_set:
              # We may be here because the original address was questionable. If
              # only other questionable ones are available then there's no point
              # changing the address. We only change if the old address wasn't
              # one of the questionable ones already.
              return random.choice(list(questionable_set))
  
      # We got nothing...
      return None
docs: Randomly choose a different host from a list of hosts.
  
      Pick from fully healthy IPs first (neither failed nor questionable).
      If we don't have any of those, pick from questionable ones next.
  
      If no suitable hosts can be found in the list (if it's empty or all hosts
      are in the failed_ips list) it will return None.
  
      The old IP (if any) is passed in. We will try to avoid returning this same
      old IP under the right circumstances. If no old IP is known, None can be
      passed in for it instead.