[Tutor] Nested list comprehensions

John Fouhy john at fouhy.net
Mon May 15 01:55:38 CEST 2006


On 15/05/06, w chun <wescpy at gmail.com> wrote:
> anyone know if list comps work the same way in haskell?

Slightly not what you asked, but you can do some funky things with
list comprehensions in Haskell.

Check this out:

fibs = 0 : 1 : [ a + b | (a, b) <- zip fibs (tail fibs)]

The python translation would be something like:

fibs = [0, 1] + [ a+b for (a, b) in zip(fibs, fibs[1:])]

But you can't quite do that in python :-)

-- 
John.


More information about the Tutor mailing list