def group(by_col_names, cur=None, rows=None, col_names=None, to_dict=False):

    if col_names is None:
        assert cur is not None, 'You must specify cur or col_names.'
        col_names = extract_col_names(cur)

    if rows is None:
        assert cur is not None, 'You must specify cur or rows.'
        rows = cur

    name_index_map = dict((name,idx) for idx,name in enumerate(col_names))
    key_indexes = tuple(name_index_map.get(name) for name in by_col_names)
    key_func = lambda row: tuple(row[i] for i in key_indexes)

    for key_values, rows_islice in groupby(rows, key_func):

        # TODO: the performance

        row = [list(col) for col in izip(*rows_islice)]
        for key_index, key_value in izip(key_indexes, key_values):
            row[key_index] = key_value

        if to_dict:
            yield one_to_dict(row=row, col_names=col_names)
        else:
            yield tuple(row)
Inspect the value of the expression
dataset/ETHPy150Open moskytw/mosql/mosql/db.py/group--crossover with--dataset/ETHPy150Open uwdata/termite-data-server/web2py/gluon/contrib/qdb.py/Frontend.do_eval