import random


def choose_faction_appropriate( fac, full_list ):
    """Filter a list of species or jobs based on the provided faction."""
    candidates = list()
    if fac:
        for pcs in full_list:
            if fac.primary in pcs.TAGS or fac.secondary in pcs.TAGS:
                candidates.append( pcs )
    return random.choice( candidates or full_list )