> Quite frequently, I find the need to iterate over two sequences at
the
> same time, and I have a bit of a hard time finding a way to do this
in a
> "pythonic" fashion. One example is a dot product. The straight-ahead
> C-like way of doing it would be:
>
> def dotproduct(a, b):
>    psum = 0
>    for i in range(len(a)):
>        psum += a[i]*b[i]
>    return psum

for this particular example, the most pythonic way is to do nothing at
all, or, if you must call it dotproduct,
>>> from Numeric import dot as dotproduct

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to