Sorting troubles

Anton Vredegoor anton.vredegoor at gmail.com
Mon May 14 15:40:11 EDT 2007


seyensubs at yahoo.com wrote:
> I see. I figured that list comprehensions made another list(duh), but
> I thought I could relink the object(List) to the new list and keep it
> once the function ended.
> 
> Is it possible to pass a reference(to an object.. Like 'List',
> basically) to a function and change the reference to point to
> something created inside a function? Or all data unreturned from a
> function is lost and no references kept?(The second, I'd guess, since
> it's local temporary scope, but you never know, maybe Python can :) )

Maybe this (untested):

def qsort(seq):
     if seq:
         pivot = seq.pop()
         Q = L,R = [],[]
         for x in seq:
             Q[x>=pivot].append(x)
         qsort(R)
         seq[:] = L+[pivot]+R

A.



More information about the Python-list mailing list