News for hackers. Stuff that matters.
Re:Python iteration by AncientPC on Wednesday April 25, 2012 @03:16PM (#3890546)
For example, trying to solve this problem (CodeJam 2008 minimum scalar product):

You are given two vectors v1=(x1,x2,...,xn) and v2=(y1,y2,...,yn). The scalar product of these vectors is a single number, calculated as x1y1+x2y2+...+xnyn.

Haskell:

  sum(zipWith (*) [1,2,3][3,2,1])
Python is not inherently functional, just supports a few convenience idioms. It has zip, but no zipWith. As a result you have to use list comprehension to perform the same:

  sum([x*y for (x,y) in zip([1,2,3][3,2,1])])
Re:Python iteration by Lycanthrope on Wednesday April 25, 2012 @04:23PM (#3890872)
You can use map with several iterables:

  sum(map(operator.mul, [1,2,3], [3,2,1]))