Converting (and back) discontinuous values to continuous values in Python 2
<p>Let's say I have a list of:</p>

<p><code>5 10 10 20 50 50 20</code></p>

<p>(there are 4 distinguish numbers).</p>

<p>I want to convert them to:</p>

<p><code>0 1 1 2 3 3 2</code></p>

<p>(then convert back to the original form).</p>

<p>There are tons of ways to do that, but I am not sure what is the best and Pythonic way?</p>

<p>(a way is to generate a set, convert the set to a list, sort the list, then generate output by the sorted list, but I think it is not the best one)</p>