Function - Irish County extract from full address

PHOTO EMBED

Thu Mar 11 2021 15:14:49 GMT+0000 (Coordinated Universal Time)

Saved by @stephenb30 #python

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)  
content_copyCOPY