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 :
def sort_Two_values(list):
Sorted_List=[]
Sorted_List.append(list[0])
for i in range(1,len(list)):
if (list[i-1]>list[i]):
Sorted_List.insert(0,list[i])
elif (list[i-1]<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
sort_Two_values([1,0,0,0,0,0,1,1,0])
It seems to be working well!
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 !