Compose a function that sorts a list known to have exactly three values efficiently (Sage(python))
<p>First of all I am not allow to use any of the internal command that sort the list not any of the other sorted method such as Selection, buble. 
Compose a function that sorts a list known to have exactly two values
this is what I have done : </p>

<pre><code>def sort_Two_values(list):
Sorted_List=[]
Sorted_List.append(list[0])
for i in range(1,len(list)):
    if (list[i-1]&gt;list[i]):
        Sorted_List.insert(0,list[i])
    elif (list[i-1]&lt;list[i]):
        Sorted_List.append(list[i])
    else:
        if (list[i]==Sorted_List[0]):
            Sorted_List.insert(0,list[i])
        else:
            Sorted_List.append(list[i])
return Sorted_List
</code></pre>

<p>sort_Two_values([1,0,0,0,0,0,1,1,0])</p>

<p>It seems to be working well! </p>

<p>Now, I am trying to do that for three values. For example [1,0,0,0,2,2,1,0,0,2] 
Would someone help me out with that ! </p>

<p>All you needs is to push <code>0 to beginning, 2 to last</code> of list and <code>1 will remain wherever it is</code>.
By the end of the loop, you will have a sorted list. </p>

python sage