def _query(data, predicate=None, key=None, reverse=False):
    """Query data and return results as a list of items.

    Args:
        data: list of lists or list of tuples
        predicate: custom function for filtering results.
        key: custom comparison key function for sorting results.
            Set to get_identity method to sort on identity.
        reverse: If set to True, then the list elements are sorted
            as if each comparison were reversed.

    Returns:
        list: list of items
    """
    if predicate:
        result = list(filter(predicate, data))
    else:
        result = data[:]

    if key or reverse:
        result = sorted(result, key=key, reverse=reverse)

    return result