[Tutor] sorting algorithm

C.T. Matsumoto c.t.matsumoto at gmail.com
Fri Mar 12 18:09:45 CET 2010


I've change the code and I think I have what you were talking about.

def mysort(list_): 
 

     for i in xrange(0, len(list_)): 
 

         pos = i 
 

         for j in xrange(pos+1, len(list_)): 
 

             if list_[i] > list_[j]: 
 

                 pos = j 
 

                 list_[i], list_[j] = list_[j], list_[i]

I finally started to think that the while couldn't remain. But if I look 
at this the thing that I don't get is the 'xrange(pos+1, len(list_))' 
snippet. What confused me was how did a new position get passed 
xrange(), when I do not see where it that was happening. Is 'pos' a 
reference to the original pos in the xrange snippet?

T


More information about the Tutor mailing list