Re: Sorting troubles

2007-05-16 Thread Aether . Singularity
On May 15, 11:54 am, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Mon, 14 May 2007 21:45:26 -0700, seyensubs wrote: > > Ah, I see, just slicing it like that.. nice! But after doing some timing > > tests, the version that's in place and using partitions is about twice > > faster than the non hybr

Re: Sorting troubles

2007-05-15 Thread Steven D'Aprano
On Mon, 14 May 2007 21:45:26 -0700, seyensubs wrote: > Ah, I see, just slicing it like that.. nice! But after doing some timing > tests, the version that's in place and using partitions is about twice > faster than the non hybrid qSort. The hybrid one, with insertionsSort > used for smaller lists

Re: Sorting troubles

2007-05-14 Thread Terry Reedy
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Teach said that the optimal threshold in hybrids is 14-16, but guess | he wasn't so right after all =\\ The overhead of using insertion sort | on a longer list turns out to be faster than just piling on | recursions, when confronted wi

Re: Sorting troubles

2007-05-14 Thread seyensubs
On May 15, 5:35 am, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Mon, 14 May 2007 09:49:56 -0700, Thomas Nelson wrote: > > The thing is that [x for x in List[1:]...] is a brand new list created > > by iterating over the old one. > > How about: > > qSortHelp(List): > > newlist = qSort(List) >

Re: Sorting troubles

2007-05-14 Thread Steven D'Aprano
On Mon, 14 May 2007 09:49:56 -0700, Thomas Nelson wrote: > The thing is that [x for x in List[1:]...] is a brand new list created > by iterating over the old one. > How about: > qSortHelp(List): > newlist = qSort(List) > for i, val in enumerate(newlist): > List[i] = val > You have

Re: Sorting troubles

2007-05-14 Thread Anton Vredegoor
[EMAIL PROTECTED] 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 chan

Re: Sorting troubles

2007-05-14 Thread Terry Reedy
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] |I have the following implementations of quicksort and insertion sort: | | def qSort(List): |if List == []: return [] |return qSort([x for x in List[1:] if x< List[0]]) + List[0:1] + \ | qSort([x for x in List[1:] if x>

Re: Sorting troubles

2007-05-14 Thread seyensubs
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 somethin

Re: Sorting troubles

2007-05-14 Thread Nick Vatamaniuc
On May 14, 12:05 pm, [EMAIL PROTECTED] wrote: > I have the following implementations of quicksort and insertion sort: > > def qSort(List): > if List == []: return [] > return qSort([x for x in List[1:] if x< List[0]]) + List[0:1] + \ >qSort([x for x in List[1:] if x>=List[0]]) >

Re: Sorting troubles

2007-05-14 Thread Thomas Nelson
On May 14, 11:05 am, [EMAIL PROTECTED] wrote: > I have the following implementations of quicksort and insertion sort: > > def qSort(List): > if List == []: return [] > return qSort([x for x in List[1:] if x< List[0]]) + List[0:1] + \ >qSort([x for x in List[1:] if x>=List[0]]) >

Sorting troubles

2007-05-14 Thread seyensubs
I have the following implementations of quicksort and insertion sort: def qSort(List): if List == []: return [] return qSort([x for x in List[1:] if x< List[0]]) + List[0:1] + \ qSort([x for x in List[1:] if x>=List[0]]) def insertSort(List): for i in range(1,len(List)):