code: def _cmp_by_med(path1, path2):
      
      def get_path_med(path):
          med = path.get_pattr(BGP_ATTR_TYPE_MULTI_EXIT_DISC)
          if not med:
              return 0
          return med.value
  
      med1 = get_path_med(path1)
      med2 = get_path_med(path2)
  
      if med1 == med2:
          return None
      elif med1 < med2:
          return path1
      return path2
docs: Select the path based with lowest MED value.
  
      If both paths have same MED, return None.
      By default, a route that arrives with no MED value is treated as if it
      had a MED of 0, the most preferred value.
      RFC says lower MED is preferred over higher MED value.