[Tutor] quicksort using list comprehension
Kent Johnson
kent37 at tds.net
Sat Apr 9 21:50:20 CEST 2005
I think you have to return a value when len(t) <= 1. You don't return anything which means you
return None which can't be added to a list.
Kent
Logesh Pillay wrote:
> 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
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list