parameters: (nb)
docstring: Walk through the notebook cells and convert exercise2 Markdown cells
      containing fenced python code to exercise2 code cells.
docstring_summary: Walk through the notebook cells and convert exercise2 Markdown cells
      containing fenced python code to exercise2 code cells.
docstring_tokens: Walk through the notebook cells and convert exercise2 Markdown cells containing fenced python code to exercise2 code cells .
function: def convert_exercise2_to_code(nb):
      """
      Walk through the notebook cells and convert exercise2 Markdown cells
      containing fenced python code to exercise2 code cells.
      """
      for i, cell in enumerate(nb['cells']):
          if 'solution2' in cell['metadata']:
              cell['metadata']['solution2'] = 'shown'
          # convert solution markdown cells into code cells
          if cell['cell_type'] == 'markdown' and 'solution2' in cell['metadata'] \
                  and 'solution2_first' not in cell['metadata']:
              lines = cell['source'].strip().split('\n')
              if lines[0].strip() == '```python' and lines[-1].strip() == '```':
                  source = '\n'.join(lines[1:-1]).strip()
                  nb['cells'][i] = nbformat.v4.new_code_cell(source=source)
                  nb['cells'][i]['metadata'] = cell['metadata']
                  nb['cells'][i]['metadata']['solution2'] = 'shown'
function_tokens: def convert_exercise2_to_code ( nb ) : for i , cell in enumerate ( nb [ 'cells' ] ) : if 'solution2' in cell [ 'metadata' ] : cell [ 'metadata' ] [ 'solution2' ] = 'shown' # convert solution markdown cells into code cells if cell [ 'cell_type' ] == 'markdown' and 'solution2' in cell [ 'metadata' ] and 'solution2_first' not in cell [ 'metadata' ] : lines = cell [ 'source' ] . strip ( ) . split ( '\n' ) if lines [ 0 ] . strip ( ) == '```python' and lines [ - 1 ] . strip ( ) == '```' : source = '\n' . join ( lines [ 1 : - 1 ] ) . strip ( ) nb [ 'cells' ] [ i ] = nbformat . v4 . new_code_cell ( source = source ) nb [ 'cells' ] [ i ] [ 'metadata' ] = cell [ 'metadata' ] nb [ 'cells' ] [ i ] [ 'metadata' ] [ 'solution2' ] = 'shown'