def select(result, keys):
    """Create new list of dictionaries from list of dictionaries,
    which contains only specified keys. Can be also used for change
    dictionary keys.
    example #1:
    SQL SELECT foo, bar, foobar FROM data;
    select(data, ['foo', 'bar', 'foobar'])

    example #2:
    SQL SELECT foo AS bar, ... FROM data;
    select(data, {'foo': 'bar', ...}

    :type keys: list or dict
    :param keys: Keys which will be included in result.
    :param result: List of dictionaries
    :return: List of dictionaries
    """
    if isinstance(keys, dict):
        return [{keys[key]: orig[key] for key in keys} for orig in result]
    else:
        return [{key: orig[key] for key in keys} for orig in result]