Re: [Tutor] Iterating over two sequences in "parallel"

2009-11-28 Thread Rich Lovely
2009/11/28 Wayne Werner : > > > On Sat, Nov 28, 2009 at 6:59 AM, Dave Angel wrote: >> >> And if the lists are large, use  itertools.izip() which works the same, >> but produces an iterator. >> >> Note that if the lists are not the same length, I think it stops when the >> shorter one ends. > > But

Re: [Tutor] Iterating over two sequences in "parallel"

2009-11-28 Thread Wayne Werner
On Sat, Nov 28, 2009 at 6:59 AM, Dave Angel wrote: > > And if the lists are large, use itertools.izip() which works the same, but > produces an iterator. > > Note that if the lists are not the same length, I think it stops when the > shorter one ends. > But you can use izip_longest: import ite

Re: [Tutor] Iterating over two sequences in "parallel"

2009-11-28 Thread Dave Angel
Jose Amoreira wrote: Hi! I want to process corresponding elements of two lists, sequentially. Call the lists list1 and list2, and assume they have equal lengths. I can do something like for index in range(len(list1)): process(list1[index], list2[index]) But I find it somehow rather ugly,

Re: [Tutor] Iterating over two sequences in "parallel"

2009-11-28 Thread Lie Ryan
On 11/28/2009 10:03 PM, Jose Amoreira wrote: Yes, Robert, that does it! Thanks a lot! Have a nice weekend! Jose don't forget zip() built-in function: for x, y in zip(list1, list2): print x, y ___ Tutor maillist - Tutor@python.org To unsubscrib

Re: [Tutor] Iterating over two sequences in "parallel"

2009-11-28 Thread Robert Johansson
Hi! I want to process corresponding elements of two lists, sequentially. Call the lists list1 and list2, and assume they have equal lengths. I can do something like for index in range(len(list1)): process(list1[index], list2[index]) But I find it somehow rather ugly, because we generate yet

Re: [Tutor] Iterating over two sequences in "parallel"

2009-11-28 Thread Jose Amoreira
Yes, Robert, that does it! Thanks a lot! Have a nice weekend! Jose On Saturday 28 November 2009 10:54:56 am Robert Johansson wrote: > Hi! > I want to process corresponding elements of two lists, sequentially. Call > the > lists list1 and list2, and assume they have equal lengths. I can do > someth

[Tutor] Iterating over two sequences in "parallel"

2009-11-28 Thread Jose Amoreira
Hi! I want to process corresponding elements of two lists, sequentially. Call the lists list1 and list2, and assume they have equal lengths. I can do something like for index in range(len(list1)): process(list1[index], list2[index]) But I find it somehow rather ugly, because we generate yet