Snippets

Lilian Besson (Naereen) prod function for Python 2 or 3K (product of the values of an iterator)

Updated by Lilian Besson (Naereen)

File prod function for Python 2.py Modified

  • Ignore whitespace
  • Hide word diff
 def prod(iterator):
     """ Compute the product of the values in the iterator.
     
-    - Empty product is 1."""
+    - Empty product is 1.
+    - Code compatible with Python 2 and 3 (2.6 or higher)
+    """
     p = 1
     for x in iterator:
         p *= x
Created by Lilian Besson (Naereen)

File prod function for Python 2.py Added

  • Ignore whitespace
  • Hide word diff
+def prod(iterator):
+    """ Compute the product of the values in the iterator.
+    
+    - Empty product is 1."""
+    p = 1
+    for x in iterator:
+        p *= x
+    return p
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.