Endorsement of list comprehensions
Aahz
aahz at pythoncraft.com
Sat May 3 00:20:33 EDT 2003
In article <mailman.1051903579.23823.python-list at python.org>,
Skip Montanaro <skip at pobox.com> wrote:
>
> def qsort2(lst):
> if len(lst) == 0:
> return []
> else:
> x = lst[0]
> return (qsort2([i for i in lst[1:] if i<x]) +
> [x] +
> qsort2([i for i in lst[1:] if i>=x])
>
>I know this will probably sound odd, but for me, the first time I saw the
>list comprehension expression of quicksort was the first time it was
>immediately apparent to me how quicksort worked.
Huh! You're right! (Not that I ever put that much effort into
understanding quicksort before, but this is indeed easy to understand.)
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"In many ways, it's a dull language, borrowing solid old concepts from
many other languages & styles: boring syntax, unsurprising semantics,
few automatic coercions, etc etc. But that's one of the things I like
about it." --Tim Peters on Python, 16 Sep 93
More information about the Python-list
mailing list