Re: [Tutor] Multiple Simultaneous Loops

2005-09-15 Thread Alan G
> for f, x in bunch_of_files, range(z): ... > Or maybe can I access the number of times the > loop has run? I think thats what enumerate does... >>> for x,y in enumerate([1,3,5]): ... print x,y ... 0 1 1 3 2 5 >>> Yep, looks like what you need. Alan G Author of the Learn to Program web

Re: [Tutor] Multiple Simultaneous Loops

2005-09-15 Thread Ed Singleton
Wonderful, thank you all of you. zip, enumerate, and count seem to do everything I want, though I do think for f, x in bunch_of_files, range(z): is a little more intuitive than for f, x in zip(bunch_of_files, range(z)): Thanks Ed On 15/09/05, Kent Johnson <[EMAIL PROTECTED]> wrote: > Ed Sing

Re: [Tutor] Multiple Simultaneous Loops

2005-09-15 Thread Kent Johnson
Ed Singleton wrote: > I roughly want to be able to do: > > for f, x in bunch_of_files, range(z): > > so that x iterates through my files, and y iterates through something else. > > Is this something I can do? In the general case use zip(): for f, x in zip(bunch_of_files, range(z)): In this cas

Re: [Tutor] Multiple Simultaneous Loops

2005-09-15 Thread Pierre Barbier de Reuille
You have a much simpler solution ! As this is a most common task to iterate on a sequence while keeping track of the index, there is an object just for that : for i,x in enumerate(iterable): # Here "i" is the index and "x" the element Also, to get some "advance" iteration schemes, have a lot at

Re: [Tutor] Multiple Simultaneous Loops

2005-09-15 Thread Andre Engels
On 9/15/05, Ed Singleton <[EMAIL PROTECTED]> wrote: > I roughly want to be able to do: > > for x, y in bunch_of_files, range(z): > > so that x iterates through my files, and y iterates through something else. > > Is this something I can do? It's not fully clear to me what you want to do. Do you

Re: [Tutor] Multiple Simultaneous Loops

2005-09-15 Thread Pujo Aji
assume: you have two list with the same size L1 = [1,2,3] L2 = [11,22,33]   you can zip the L1 and L2 into L L = zip(L1,L2)  # L = [(1,11),(2,22),(3,33)]    then you can process: for x in L:   dosomething(x[0])...   dosomething(x[1])...   I'm not so sure about your problem but If you want to do som