<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def select_rows(cols, rows, mode='list', cast=True):
 """ Yield data selected from rows. It is sometimes useful to select a subset of data from a profile. This function selects the data in *cols* from *rows* and yields it in a form specified by *mode*. Possible values of *mode* are: ================== ================= ========================== mode description example `['i-id', 'i-wf']` ================== ================= ========================== `'list'` (default) a list of values `[10, 1]` `'dict'` col to value map `{'i-id': 10,'i-wf': 1}` `'row'` [incr tsdb()] row `'10@1'` ================== ================= ========================== Args: cols: an iterable of column names to select data for rows: the rows to select column data from mode: the form yielded data should take cast: if `True`, cast column values to their datatype (requires *rows* to be :class:`Record` objects) Yields: Selected data in the form specified by *mode*. """

    mode = mode.lower()
    if mode == 'list':
        modecast = lambda cols, data: data
    elif mode == 'dict':
        modecast = lambda cols, data: dict(zip(cols, data))
    elif mode == 'row':
        modecast = lambda cols, data: encode_row(data)
    else:
        raise ItsdbError('Invalid mode for select operation: {}\n'
                         '  Valid options include: list, dict, row'
                         .format(mode))
    for row in rows:
        try:
            data = [row.get(c, cast=cast) for c in cols]
        except TypeError:
            data = [row.get(c) for c in cols]
        yield modecast(cols, data)