import re


def update_zipcode(zipcode):
    """Clean postcode to a uniform format of 5 digit; Return updated postcode"""
    if re.findall(r'^\d{5}$', zipcode): # 5 digits 02118
        valid_zipcode = zipcode
        return valid_zipcode
    elif re.findall(r'(^\d{5})-\d{3}$', zipcode): # 8 digits 02118-029
        valid_zipcode = re.findall(r'(^\d{5})-\d{3}$', zipcode)[0]
        return valid_zipcode
    elif re.findall(r'(^\d{5})-\d{4}$', zipcode): # 9 digits 02118-0239
        valid_zipcode = re.findall(r'(^\d{5})-\d{4}$', zipcode)[0]
        return valid_zipcode
    elif re.findall(r'CA\s*\d{5}', zipcode): # with state code CA 02118
        valid_zipcode =re.findall(r'\d{5}', zipcode)[0]  
        return valid_zipcode  
    else: #return default zipcode to avoid overwriting
        return zipcode