Overwrite previous output in jupyter notebook
<p>Let's assume I have a part of code that runs for some specific amount of time and each 1 second outputs something like this: <code>iteration X, score Y</code>. I will substitute this function with my black box function:</p>

<pre><code>from random import uniform
import time

def black_box():
    i = 1
    while True:
        print 'Iteration', i, 'Score:', uniform(0, 1)
        time.sleep(1)
        i += 1
</code></pre>

<p>Now when I run it in <a href="https://tmp55.tmpnb.org/user/tqEpj95wJzL3/tree" rel="noreferrer">Jupyter notebook</a>, it output a new line after each second:</p>

<pre><code>Iteration 1 Score: 0.664167449844
Iteration 2 Score: 0.514757592404
...
</code></pre>

<p>Yes, after when the output becomes too big, the html becomes scrollable, but the thing is that I do not need any of these lines except of currently the last one. So instead of having <code>n</code> lines after <code>n</code> seconds, I want to have only <code>1</code> line (the last one) shown. </p>

<p>I have not found anything like this in documentation or looking through magic. <a href="https://stackoverflow.com/questions/37956788/how-to-overwrite-the-previous-print-line-in-jupyter-ipython">A question</a> with almost the same title but irrelevant.</p>