[Tutor] Re: Tutor Digest, Vol 14, Issue 32

Rick Muller rmuller at sandia.gov
Sat Apr 9 22:29:25 CEST 2005


On Apr 9, 2005, at 1:54 PM, tutor-request at python.org wrote:
>
> Message: 8
> Date: Sat, 09 Apr 2005 20:58:49 +0200
> From: "Logesh Pillay" <logesh at iafrica.com>
> Subject: [Tutor] quicksort using list comprehension
> To: "Discussion for learning programming with Python"
> 	<tutor at python.org>
> Message-ID: <opsoza0br1reljbd at laptop>
> Content-Type: text/plain; format=flowed; delsp=yes;
> 	charset=iso-8859-15
>
> 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
>

I think the following recipe is what you want:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66473

Rick




More information about the Tutor mailing list