From fc11fe941ad6cfa9a3bab5cd84cc6f0289906299 Mon Sep 17 00:00:00 2001 From: John Yani Date: Mon, 5 Aug 2013 13:00:16 +0300 Subject: [PATCH] Unrealistic example to use reduce. Sum is more appropriate here. --- uapycon2012/index.html | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/uapycon2012/index.html b/uapycon2012/index.html index 675446b..a41418e 100755 --- a/uapycon2012/index.html +++ b/uapycon2012/index.html @@ -453,18 +453,16 @@

Currying (standard library)

Good function is small function

+
>>> ss = ["UA", "PyCon", "2012"]

Bad

-
>>> ss = ["UA", "PyCon", "2012"]
->>> reduce(lambda acc, s: acc + len(s), ss, 0)
+
>>> reduce(lambda acc, s: acc + len(s), ss, 0)
 11

Not bad...

-
>>> ss = ["UA", "PyCon", "2012"]
->>> reduce(lambda l,r: l+r, map(lambda s: len(s), ss))
+
>>> reduce(lambda l,r: l+r, map(lambda s: len(s), ss))
 11

Good

-
>>> ss = ["UA", "PyCon", "2012"]
->>> reduce(operator.add, map(len, ss))
+
>>> sum(map(len, ss))
 11