I have the following function which maps the first two letters of a postcode to a country. However, it does not recognise when there is only one letter followed by a number i.e. "B4" or "N1, so it does not map it and returns "Other".
What could I do to make it recognise single letters followed by numbers?
My function is:
def parse_to_find_country(x):
if (x == "BT"):
return "Northern Ireland"
elif (x == "CF")|(x == "SA")|(x == "LD")|(x == "LL")|(x == "NP"):
return "Wales"
elif (x == "AB")|(x == "DD")|(x == "DG")|(x == "EH")|(x == "FK")|(x == "G")|(x == "HS")|(x == "IV")|(x == "KA")|(x == "KN")|(x == "KY")|(x == "ML")|(x == "PA")|(x == "PH")|(x == "TD")|(x == "ZE"):
return "Scotland"
elif (x == "AL")|(x == "B")|(x == "BA")|(x == "BB")|(x == "BD")|(x == "BH")|(x == "BL")|(x == "BN")|(x == "BR")|(x == "BS")|(x == "CA")|(x == "CB")|(x == "CH")|(x == "CM")|(x == "CO")|(x == "CR")|(x == "CT")|(x == "CV")|(x == "CN")|(x == "DA")|(x == "DE")|(x == "DH")|(x == "DL")|(x == "DN")|(x == "DT")|(x == "DY")|(x == "E")|(x == "EC")|(x == "EH")|(x == "EN")|(x == "EX")|(x == "FY")|(x == "GL")|(x == "GU")|(x == "HA")|(x == "HD")|(x == "HG")|(x == "HP")|(x == "HR")|(x == "HU")|(x == "HX")|(x == "IG")|(x == "IP")|(x == "KT")|(x == "L")|(x == "LA")|(x == "LE")|(x == "LN")|(x == "LS")|(x == "LU")|(x == "M")|(x == "ME")|(x == "M")|(x == "MK")|(x == "N")|(x == "NE")|(x == "NG")|(x == "NN")|(x == "NR")|(x == "NW")|(x == "OL")|(x == "OX")|(x == "PE")|(x == "PL")|(x == "PO")|(x == "PR")|(x == "RG")|(x == "RH")|(x == "RM")|(x == "S")|(x == "SE")|(x == "SG")|(x == "SK")|(x == "SL")|(x == "SM")|(x == "SN")|(x == "SO")|(x == "SP")|(x == "SR")|(x == "SS")|(x == "ST")|(x == "SW")|(x == "SY")|(x == "TA")|(x == "TF")|(x == "TN")|(x == "TQ")|(x == "TR")|(x == "TS")|(x == "TW")|(x == "UB")|(x == "W")|(x == "WA")|(x == "WC")|(x == "WD")|(x == "WF")|(x == "WN")|(x == "WR")|(x == "WS")|(x == "WV")|(x == "YO"):
return "England"
else:
return "Other"