Re: Iteration over two sequences

2005-02-11 Thread Scott David Daniels
David Isaac wrote: "Scott David Daniels" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]: Numarray is the future, Numeric is the "past", This statement is not obviously true. See the recent discussion on the developer lists. (Search for Numeric3.) Alan Isaac I stand corrected. Sorry

Re: Iteration over two sequences

2005-02-11 Thread David Isaac
"Scott David Daniels" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]: > Numarray is the future, Numeric is the "past", This statement is not obviously true. See the recent discussion on the developer lists. (Search for Numeric3.) Alan Isaac -- http://mail.python.org/mailman/listin

Re: Iteration over two sequences

2005-01-13 Thread Diez B. Roggisch
My example is somewhat flawed because it assigns a and b the values of the iteration - so in the end, b is 'c', and only setting a to [1,2] will show your results. Use c and d for the variables in the for-statments, and things work as expected. -- Regards, Diez B. Roggisch -- http://mail.python

Re: Iteration over two sequences

2005-01-12 Thread Terry Reedy
"It's me" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >I tried this and I got: > [(1, 'a'), (2, 'b'), (3, 'c')] > But if I change: > a=[1,2] > I got: > [(1, 'c')] > Why is that? I thought I should be getting: > [(1, 'a'),(2,'b')] > ? Cut and paste the actual input and output

Re: Iteration over two sequences

2005-01-12 Thread Scott David Daniels
Henrik Holm wrote: 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 import dot as dotp

Re: Iteration over two sequences

2005-01-12 Thread John Lenton
> Downloading, installing, and getting to know numerical modules for > Python is mext on my list :). However, I was under the impression that > Numarray is preferred to Numeric -- is that correct? Are these two > competing packages? (Hopefully this is not flame war bait...) Numeric's dot uses, if

Re: Iteration over two sequences

2005-01-12 Thread Steven Bethard
Henrik Holm wrote: 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 import dot as dotp

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

Re: Iteration over two sequences

2005-01-12 Thread It's me
I tried this and I got: [(1, 'a'), (2, 'b'), (3, 'c')] But if I change: a=[1,2] I got: [(1, 'c')] Why is that? I thought I should be getting: [(1, 'a'),(2,'b')] ? "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > zip or izip is your friend: > > import i

Re: Iteration over two sequences

2005-01-12 Thread John Lenton
> 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 >

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 overlooking? > > Check the itertools recipes in the lib

Re: Iteration over two sequences

2005-01-12 Thread Richard Brodie
"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 overlooking? Check the itertools recipes in the library documentation. -- http://mail.python.org/mailman

Re: Iteration over two sequences

2005-01-12 Thread Paul McGuire
"Henrik Holm" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > 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

Re: Iteration over two sequences

2005-01-12 Thread Diez B. Roggisch
zip or izip is your friend: import itertools a = [1,2,3] b = ['a', 'b', 'c'] for a,b in itertools.izip(a, b): print a, b -- Regards, Diez B. Roggisch -- http://mail.python.org/mailman/listinfo/python-list