import re


def clean_place(value):
    """
    value='Portugal, Faro, Castro Marim<BR/>Portugal'
    returns 'Portugal', 'Faro', 'Castro Marim',

    value='Portugal, Faro<BR/>Portugal'
    returns 'Portugal', 'Faro'
    """
    places = re.split('<BR/>', value)  # different locations

    # split each in (country, district, council)
    places = [re.split(', ', place) for place in places]
    place = places[0]
    # remove locations not determined
    place = [location for location in place if 'não determinado' not in location]

    # fill place with Nones if incomplete
    while len(place) < 3:
        place.append(None)
    return tuple(place)