Saturday, February 27, 2010

One line quicksort in Python

Here's a one line quicksort in python. I came up with this idea after looking at a 2 lines implementation in Haskel

qsort = lambda seq: [] if not seq else qsort(filter(lambda n: n<=seq[0], seq[1:]))+[seq[0]]+qsort(filter(lambda n: n>seq[0], seq[1:]))

1 comment:

  1. sweet! I've never even tried recursion with lambda's but you know what they say about recursion with lambdas... they say they've never even tried recursion...... Mind blown

    ReplyDelete