why python annoys me
Ben Wolfson
wolfson at uchicago.edu
Sat Apr 21 00:15:09 EDT 2001
In article <3AE0F802.3983C9DB at 01019freenet.de>, "Oliver Korpilla"
<korpo at 01019freenet.de> wrote:
> Haskell Quicksort:
> qsort:: Ord a=> [a] -> [a]
> qsort [] = []
> qsort (x:xs) = [y | y <- xs, y <= x] ++ [x] ++ [y | y <- xs, y > x]
Python Quicksort:
def qsort(L):
L = list(L)
if L == []:
return []
x, xs = L[0], L[1:]
return qsort([y for y in xs if y<=x])+[x]+qsort([y for y in xs if y>x])
Though you'd be better off with a list's sort() method, of course.
--
Barnabas T. Rumjuggler
Thou hast been called, O Sleep! The friend of woe,
But 'tis the happy who have called thee so.
-- Robert Southey
More information about the Python-list
mailing list