[Tutor] quicksort using list comprehension
Logesh Pillay
logesh at iafrica.com
Sat Apr 9 20:58:49 CEST 2005
I'm trying to program quicksort using list comprehension.
The following gives me a type mismatch error for "+".
def qsort (t):
if len (t) > 1:
return qsort([x for x in t[1:] if x <= t[0]]) + [t[0]] + qsort([x
for x in t[1:] if x > t[0]])
I know this sounds strange but I have and idea it (or something similar)
worked when I last tried Python a yr or so ago. An earlier version of
Python?
Logesh Pillay
More information about the Tutor
mailing list