<jupyter_start><jupyter_text>This is a notebook that we've drafted for an upcoming class. There are some markdown prompts, cells where students must insert code, and cells where students must give text answers.We'll strip this notebook of all outputs and cell execution numbers, and format the input cells so that they're ready for submitting to students as homework templates.  Removing text within a cell`nbclean` lets you specify text *within a cell* that you wanted removed. For example, belowwe show the "master copy" of a homework question. It includes the markdown for the question,and the answer in code below.By wrapping the answer with `SOLUTION BEGIN` comments, we can use `nbclean` to scrub this andgenerate a student notebook.  Question 1* First, multiply `a` by 2* Make a plot of the result* We show an example of how the plot should appear below<jupyter_code># First we'll create 'a'
a = np.arange(10)

### SOLUTION BEGIN
# We can use the STUDENT ANSWER block to remove only part
# of the cell (as well as the output). This way you can give
# students prompts or help them along with some partial answers.
b = a * 2
plt.plot(b)

# Students will now see a replacement answer prompt, and
# won't see the solution. By default the replacement answer will
# raise an error to make sure students don't miss it.
### SOLUTION END<jupyter_output><empty_output><jupyter_text>Note that the **output** of the cell wasn't changed (you can control that separately,see below for more details).  Cells without the matching text won't be modifiedHere's an example of how we can plot the two variables against each other.<jupyter_code># Cells without any of the text that we search for using the
# strip_notebooks function won't be affected at all.
plt.scatter(a, a*2)<jupyter_output><empty_output><jupyter_text>Text flags work within Markdown cells tooFinally, it is often useful to ask students "conceptual" questions that are answered with prose rather than with code. It's clunky to use code cells for this, so `create_answer_cells` also works with markdown cells using the same syntax as before:For example, we could ask students:> $y$ is the square of $x$, explain the relationship between x and y with an equation. SOLUTION BEGIN$y = x ^ 2$ SOLUTION ENDAnd the above will be removed with a prompt for students to answer.  Removing cell parts + filtering with tagsWith `nbclean` you can remove parts of cells (such as `stderr`, the content block, output images, etc).This can be applied to all cells, or applied to a subset by using **Cell tags**.To add a cell tag, click `View -> Cell Toolbar -> Tags` to see the tag toolbars.You can define arbitrary tags to each cell. Then, when you run `nbclean` on the notebook,you can cause any command to *only* be applied to cells with a given tag (see the [modify_notebooks.ipynb](../modify_notebooks.ipynb) notebook to see this in action).Many different tags have been added to the cells below, each one will be used in [modify_notebooks.ipynb](../modify_notebooks.ipynb)to scrub different parts of the cell.<jupyter_code># This cell's output will be hidden
plt.plot(np.random.randn(50))
# This cell's content will be hidden
plt.scatter(np.random.randn(50), np.random.randn(50))
# The sterr output of this cell will be hidden
from warnings import warn
print("This was a triumph.")
warn("I'm making a note here.")
plt.text(.5, .5, "Huge success.")
# This cell will be removed entirely
plt.hist(np.random.randn(50))<jupyter_output><empty_output><jupyter_text>Removing empty cellsYou can also remove empty cells if you wish!<jupyter_code># The above cell should be removed!<jupyter_output><empty_output><jupyter_text>Removing cells with text in itThe following cell should be removed<jupyter_code># HIDDEN

my_cell = "this shouldn't show up"<jupyter_output><empty_output><jupyter_text>This cell shouldn't be touched<jupyter_code># There are no removal / modification tags in this cell
print("I'm not gonna cook it")
warn("But I'll order it from zanzibar")
plt.hist(np.random.randn(50))<jupyter_output>I'm not gonna cook it
{'fraction_non_alphanumeric': 0.07257072570725707, 'fraction_numerical': 0.004674046740467405, 'mean_word_length': 5.114285714285714, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '308912', 'license': 'MIT', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1132, 'n_words': 579, 'path': 'examples/test_notebooks/test_notebook.ipynb', 'repo_name': 'betatim/nbclean', 'size': '4065'}