Something is rotten in Denmark...
Jussi Piitulainen
jpiitula at ling.helsinki.fi
Fri Jun 3 02:17:11 EDT 2011
rusi writes:
> So I tried:
> Recast the comprehension as a map
> Rewrite the map into a fmap (functionalmap) to create new bindings
>
> def fmap(f,lst):
> if not lst: return []
> return [f(lst[0])] + fmap(f, lst[1:])
>
> Still the same effects.
>
> Obviously I am changing it at the wrong place...
>>> fs = [(lambda n : n + i) for i in range(10)]
>>> [f(1) for f in fs]
[10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
>>> fs = list(map(lambda i : lambda n : n + i, range(10)))
>>> list(map(lambda f : f(1), fs))
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
More information about the Python-list
mailing list