Spinsels op het web
actions » SearchLogin 124 articles • 07 Aug 2008

Article with comments

Monday, 22 Nov 2004

permalink Quicksort

Quicksort using list comprehensions:

import random

def quicksort(lst): 
     if len(lst) <= 1: return lst 
     pivot = lst[random.randrange(len(lst))]
      
     left =   [x for x in lst if x <  pivot] 
     middle = [x for x in lst if x == pivot] 
     right =  [x for x in lst if x >  pivot] 

     return quicksort(left) + middle + quicksort(right)
• Wrote irmen at 21:00 (edited 1×, last on 14 Feb 2005) | read 24× | Add comment

Comments (0)

No comments for this article yet.

Write a comment

Your name  
E-mail   (only visible for blog owner)
Homepage
Text:

[b] [i] [u] [tt] [center] [code] [quote] [url] [url=] [img] [@] [@@] [@:]
detailed help about markup
You must answer the following to be able to submit.
Type the letters you see in the image.
(Unreadable? Click 'Preview' for a new one)

Process times: page=0.036 request=0.061 cpu=0.060