def makeStandardPhoneNumber(internationalCode, rest):
    """
    Make a standard phone number by appending rest to the internationalCode.
    Check the first digits rest to see if they match the NDD which must be removed
    from the number. i.e. 0 in the UK
    Example: makeStandardPhoneNumber('44', '073749135381') -> '4473749135381'
    """
    # Get the NDD code for this internationalCode
    NDD = getNDD(internationalCode)

    # if the country has an NDD, check for it and remove if it exists
    if NDD is not None:
        index = len(NDD)
        if rest[:index] == NDD:
            rest = rest[index:]
    result = internationalCode + rest
    return result
    
def getNDD(internationalCode):
    for country, iCode, NDD in internationalCodes:
        if iCode == internationalCode:
            return NDD
    return None


internationalCodes = [("United Kingdom", "44", "0"),
("United States of America", "1", "1"),
("Afghanistan ", "93", "0"),
("Albania", "355", "0"),
("Algeria", "213", "7"),
("Andorra", "376", None),
("Angola", "244", "0"),
("Antarctica", "672", None),
("Argentina", "54", "0"),
("Armenia", "374", "8"),
("Aruba", "297", None),
("Ascension", "247", None),
("Australia", "61", None),
("Australian External Territories", "672", "0"),
("Austria", "43", "0"),
("Azerbaijan", "994", "8"),
("Bahrain", "973", None),
("Bangladesh", "880", "0"),
("Belarus", "375", "8"),
("Belgium", "32", "0"),
("Belize", "501", "0"),
("Benin", "229", None),
("Bhutan", "975", None),
("Bolivia", "591", None),
("Bosnia & Herzegovina", "387", "0"),
("Botswana", "267", None),
("Brazil", "55", None),
("Brunei Darussalam", "673", "0"),
("Bulgaria", "359", "0"),
("Burkina Faso", "226", None),
("Burundi", "257", None),
("Cambodia", "855", "0"),
("Cameroon", "237", None),
("Canada", "1", "1"),
("Cape Verde Islands", "238", None),
("Central African Republic", "236", None),
("Chad", "235", None),
("Chatham Island", "64", None),
("Chile", "56", "0"),
("China (PRC)", "86", "0"),
("Christmas Island", "53", None),
("Cocos-Keeling Islands", "61", "0"),
("Colombia", "57", None),
("Comoros", "269", None),
("Congo", "242", None),
("Congo, Dem. Rep. of", "243", None),
("Cook Islands", "682", "0"),
("Costa Rica", "506", None),
("C\xf4te d'Ivoire (Ivory Coast)", "225", "0"),
("Croatia", "385", "0"),
("Cuba", "53", "0"),
("Cuba (Guantanamo Bay)", "5399", "0"),
("Cura\xe7ao", "599", None),
("Cyprus", "357", None),
("Czech Republic", "420", None),
("Denmark", "45", None),
("Diego Garcia", "246", None),
("Djibouti", "253", None),
("East Timor", "670", None),
("Easter Island", "56", None),
("Ecuador", "593", "0"),
("Egypt", "20", "0"),
("El Salvador", "503", None),
("Equatorial Guinea", "240", None),
("Eritrea", "291", "0"),
("Estonia", "372", None),
("Ethiopia", "251", "0"),
("Falkland Islands (Malvinas)", "500", None),
("Faroe Islands", "298", None),
("Fiji Islands", "679", None),
("Finland", "358", "0"),
("France", "33", None),
("French Antilles", "596", None),
("French Guiana", "594", None),
("French Polynesia", "689", None),
("Gabonese Republic", "241", None),
("Gambia", "220", None),
("Georgia", "995", "8"),
("Germany", "49", "0"),
("Ghana", "233", None),
("Gibraltar", "350", None),
("Greece", "30", None),
("Greenland", "299", None),
("Guadeloupe", "590", None),
("Guantanamo Bay", "5399", "0"),
("Guatemala", "502", None),
("Guinea-Bissau", "245", None),
("Guinea", "224", "0"),
("Guyana", "592", "0"),
("Haiti", "509", "0"),
("Honduras", "504", "0"),
("Hong Kong", "852", None),
("Hungary", "36", "6"),
("Iceland", "354", "0"),
("India", "91", "0"),
("Indonesia", "62", None),
("Iran", "98", "0"),
("Iraq", "964", "0"),
("Ireland", "353", None),
("Israel", "972", None),
("Italy", "39", None),
("Japan", "81", None),
("Jordan", "962", "0"),
("Kazakhstan", "7", "8"),
("Kenya", "254", None),
("Kiribati", "686", "0"),
("Korea (North)", "850", "0"),
("Korea (South)", "82", None),
("Kuwait", "965", "0"),
("Kyrgyz Republic", "996", "0"),
("Laos", "856", "0"),
("Latvia", "371", None),
("Lebanon", "961", None),
("Lesotho", "266", "0"),
("Liberia", "231", "22"),
("Libya", "218", "0"),
("Liechtenstein", "423", None),
("Lithuania", "370", "8"),
("Luxembourg", "352", None),
("Macao", "853", "0"),
("Macedonia (Former Yugoslav Rep of.)", "389", "0"),
("Madagascar", "261", "0"),
("Malawi", "265", None),
("Malaysia", "60", "0"),
("Maldives", "960", "0"),
("Mali Republic", "223", "0"),
("Malta", "356", "21"),
("Marshall Islands", "692", "1"),
("Martinique", "596", "0"),
("Mauritania", "222", "0"),
("Mauritius", "230", "0"),
("Mayotte Island", "269", None),
("Mexico", "52", "1"),
("Micronesia, (Federal States of)", "691", "1"),
("Moldova", "373", "0"),
("Monaco", "377", "0"),
("Mongolia", "976", "0"),
("Montenegro", "382", "0"),
("Morocco", "212", None),
("Mozambique", "258", "0"),
("Myanmar", "95", None),
("Namibia", "264", "0"),
("Nauru", "674", "0"),
("Nepal", "977", "0"),
("Netherlands", "31", "0"),
("Netherlands Antilles", "599", "0"),
("New Caledonia", "687", "0"),
("New Zealand", "64", "0"),
("Nicaragua", "505", "0"),
("Niger", "227", "0"),
("Nigeria", "234", "0"),
("Niue", "683", "0"),
("Norfolk Island", "672", None),
("Norway", "47", None),
("Oman", "968", "0"),
("Pakistan", "92", "0"),
("Palau", "680", None),
("Palestinian Settlements", "970", "0"),
("Panama", "507", None),
("Papua New Guinea", "675", None),
("Paraguay", "595", "0"),
("Peru", "51", "0"),
("Philippines", "63", "0"),
("Poland", "48", "0"),
("Portugal", "351", None),
("Qatar", "974", "0"),
("R\xe9union Island", "262", "0"),
("Romania", "40", None),
("Russia", "7", None),
("Rwandese Republic", "250", "0"),
("St. Helena", "290", None),
("St. Pierre & Miquelon", "508", "0"),
("Samoa", "685", "0"),
("San Marino", "378", "0"),
("S\xe3o Tom\xe9 and Principe", "239", "0"),
("Saudi Arabia", "966", "0"),
("Senegal", "221", "0"),
("Serbia", "381", "0"),
("Seychelles Republic", "248", "0"),
("Sierra Leone", "232", "0"),
("Singapore", "65", None),
("Slovak Republic", "421", "0"),
("Slovenia", "386", "0"),
("Solomon Islands", "677", None),
("Somali Democratic Republic", "252", None),
("South Africa", "27", "0"),
("Spain", "34", None),
("Sri Lanka", "94", "0"),
("Sudan", "249", "0"),
("Suriname", "597", None),
("Swaziland", "268", None),
("Sweden", "46", "0"),
("Switzerland", "41", "0"),
("Syria", "963", None),
("Taiwan", "886", None),
("Tajikistan", "992", "8"),
("Tanzania", "255", None),
("Thailand", "66", None),
("Timor Leste", "670", None),
("Togolese Republic", "228", None),
("Tokelau", "690", None),
("Tonga Islands", "676", None),
("Tunisia", "216", "0"),
("Turkey", "90", "0"),
("Turkmenistan", "993", "8"),
("Tuvalu", "688", None),
("Uganda", "256", None),
("Ukraine", "380", "8"),
("United Arab Emirates", "971", "0"),
("Uruguay", "598", "0"),
("Uzbekistan", "998", "8"),
("Vanuatu", "678", None),
("Vatican City", "39", None),
("Vatican City", "379", None),
("Vietnam", "84", "0"),
("Wake Island", "808", None),
("Wallis and Futuna Islands", "681", None),
("Yemen", "967", "0"),
("Zambia", "260", "0"),
("Zanzibar", "255", "0"),
("Zimbabwe", "263", "0")
]
