code: def alpha2(self, code):
          
          code = force_text(code).upper()
          if code.isdigit():
              lookup_code = int(code)
  
              def find(alt_codes):
                  return alt_codes[1] == lookup_code
  
          elif len(code) == 3:
              lookup_code = code
  
              def find(alt_codes):
                  return alt_codes[0] == lookup_code
  
          else:
              find = None
          if find:
              code = None
              for alpha2, alt_codes in self.alt_codes.items():
                  if find(alt_codes):
                      code = alpha2
                      break
          if code in self.countries:
              return code
          return ""
docs: Return the two letter country code when passed any type of ISO 3166-1
          country code.
  
          If no match is found, returns an empty string.