def County_Extract(address): counties_list = ['Carlow','Cavan','Clare', 'Cork', 'Donegal','Dublin','Galway','Kerry','Kildare','Kilkenny', 'Laois','Leitrim','Limerick','Longford','Louth','Mayo', 'Meath','Monaghan','Offaly','Roscommon','Sligo', 'Tipperary','Waterford','Westmeath', 'Wexford','Wicklow'] county_match = '' old_find_index = 0 for county in counties_list: find_index = address.upper().rfind(county.upper()) if find_index > old_find_index: county_match = county old_find_index = find_index if old_find_index != 0: CorrectCounty = county_match else: CorrectCounty = "Unknown" return(CorrectCounty)