import nbformat as nbf1from glob import glob23# Collect a list of all notebooks in the content folder4notebooks = glob("*.ipynb")56# Text to look for in adding tags7text_search_dict = {8"# Solution": "hide-cell", # Hide the cell with a button to show9}1011# Search through each notebook and look for the text, add a tag if necessary12for ipath in notebooks:13ntbk = nbf.read(ipath, nbf.NO_CONVERT)1415for cell in ntbk.cells:16cell_tags = cell.get('metadata', {}).get('tags', [])17cell_tags = []18for key, val in text_search_dict.items():19if key in cell['source']:20if val not in cell_tags:21cell_tags.append(val)22if len(cell_tags) > 0:23cell['metadata']['tags'] = cell_tags2425nbf.write(ntbk, ipath)262728