Iteration over two sequences

2005-01-12 Thread Henrik Holm
I am just starting to learn Python, mostly by going through the examples in Dive Into Python and by playing around. 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

Re: Iteration over two sequences

2005-01-12 Thread Henrik Holm
Richard Brodie <[EMAIL PROTECTED]> wrote: > "Henrik Holm" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > > I suppose I could also use a lambda here -- but is there a different, > > efficient, and obvious solution that I'm over

Re: Iteration over two sequences

2005-01-12 Thread Henrik Holm
John Lenton <[EMAIL PROTECTED]> wrote: > > 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

Closing files

2004-11-28 Thread Henrik Holm
with a one-liner as well, with lines = popen('executable').readlines() without closing the file object? Thanks, Henrik Holm -- http://mail.python.org/mailman/listinfo/python-list