def to_code(cells):
    """
    Turns the cells into Python code.

    :param cells: the cells to iterate
    :type cells: list
    :return: the generated code
    :rtype: list
    """
    result = []
    for cell in cells:
        if 'cell_type' in cell:
            if cell['cell_type'] == 'code' and 'source' in cell:
                for line in cell['source']:
                    if 'install.packages(' in line:
                        result.append('# ' + line.rstrip())
                    else:
                        result.append(line.rstrip())
            elif cell['cell_type'] == 'markdown' and 'source' in cell:
                for line in cell['source']:
                    result.append('# ' + line.rstrip())
            result.append('')
    return result
