A no-op is an operation that does... nothing.
If a function doesn't return anything, it's probably impure. If it doesn't return anything, the only reason for it to exist is to perform a side effect.
This function performs a useless computation because it doesn't return anything or perform a side effect. It's a no-op.
def square(x):
x * x
This function performs a side effect. It changes the value of the y variable that is outside of its scope. It's impure.
y = 5
def add_to_y(x):
global y
y += x
add_to_y(3)
# y = 8
The global keyword just tells Python to allow modification of the outer-scoped y variable.
Even the print function (technically) has an impure side effect! It doesn't return anything, but it does print text to the console, which is a form of I/O.
Fix the remove_emphasis function by making it pure.
remove_emphasis takes a document with any number of lines and removes any number of * characters that are at the start or end of a word. (In case you need it, here's a primer on emphasis in Markdown.)
For example, this:
I *love* Markdown.
I **really love** Markdown.
I ***really really love*** Markdown.
Should become:
I love Markdown.
I really love Markdown.
I really really love Markdown.
The problem is that remove_emphasis is currently impure – it modifies a global variable called doc. It should instead accept a document as an argument and return a new document with emphasis removed.
Once you've purified remove_emphasis, you can also delete the global doc variable.