import copy


def select(a_list, query, *, exactly=0):
    """Scan a list of dictionaries and pick ones that match the query."""

    documents = []
    counter = 0

    for item in a_list:
        if not query(item):
            continue

        documents.append(copy.deepcopy(item))

        if bool(exactly):
            counter += 1
            if counter >= exactly:
                break

    if counter >= exactly:
        if exactly == 1:
            return documents[0]
        return documents

    return None