-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 17/09/2013 18:59, Piergiuliano Bossi wrote: > [...] Non e' particolarmente interessante focalizzarsi ne' su > map/reduce ne' sulle collezioni in generale. > > Comunque, un altro esempio e' questo => puoi usare itertools.chain > per implementare una flatmap (sicuro che non vuoi il codice Python? > allora non leggere :) ) >
Non tutti conoscono Scala e sanno cosa fa flatmap. Comunque se ho capito quello che fa: ##BEGIN## def flatmap(seq, fun): for x in seq: for y in fun(x): yield y def foo(x): return [x - 1, x, x + 1] print list(flatmap([1, 2, 3, 4, 5], foo)) ##END## La list alla fine serve a stampare correttamente la sequenza "lazy" (Python non │ Haskell). > [...] Ciao Manlio -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Icedove - http://www.enigmail.net/ iEYEARECAAYFAlI4l6cACgkQscQJ24LbaUQ14wCdGiY+COvskxnqxKJZaqHllEo8 VkoAmwfL7LCDEBiBkSuCzNuyQcl9ZPt7 =XyyE -----END PGP SIGNATURE----- _______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python