Re: [Tutor] quicksort using list comprehension

2005-04-09 Thread Max Noel
On Apr 9, 2005, at 21:50, Kent Johnson wrote: 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 Yup. Here's a quicksort I did, adapting an example from the Wikipedia article on Haskell: def qsort(toSo

Re: [Tutor] quicksort using list comprehension

2005-04-09 Thread Kent Johnson
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): i

[Tutor] quicksort using list comprehension

2005-04-09 Thread Logesh Pillay
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