comprehending comprehensions
Maurix
maurix78_remove_this_ at wanadoo.es
Sat Jun 14 18:46:55 EDT 2003
Hi, as you are speaking of comprehensions, functional languages
and Haskell; i want to propose a game to the group:
Let's make some examples to see how long is python compared
with Haskell.
I've make my try, writing the famous example of qsort in Haskell
in a "functional" python:
Haskell:
qsort [] = []
qsort (x:xs) = qsort elts_lt_x ++ [x] ++ qsort elts_greq_x
where
elts_lt_x = [y | y <- xs, y < x]
elts_greq_x = [y | y <- xs, y >= x]
Python:
def qsort(list) :
if len(list)<=1 : return list
x,xs=list[0],list[1:]
elts_lt_x=[y for y in xs if y < x]
elts_greq_x=[y for y in xs if y >= x]
return qsort(elts_lt_x)+[x]+qsort(elts_greq_x)
6 lines vs 5 lines, not bad!
Someting can do it better??
I have a question too, there something in haskell that is
difficult to "copy" with python?
I like haskell for his math-style but have really something more?
More information about the Python-list
mailing list