Re: [Tutor] iterating over a sequence question..

2007-06-19 Thread Iyer
wow, very interesting thread this was..I probably learnt a lot from this than by flipping a few pages of a python text... thank you all for your interesting responses .. iyer Luke Paireepinart <[EMAIL PROTECTED]> wrote: On 6/18/07, Simon Hooper <[EMAIL PROTECTED]> wrote: Hi Luke, * On 17/0

Re: [Tutor] iterating over a sequence question..

2007-06-18 Thread Luke Paireepinart
On 6/18/07, Simon Hooper <[EMAIL PROTECTED]> wrote: Hi Luke, * On 17/06/07, Luke Paireepinart wrote: > a more expanded version that accounts for either list being the longer > one, or both being the same length, would be: > > >>> if len(t) > len(l): x = len(t) > else: x = len(l) > >>> print [

Re: [Tutor] iterating over a sequence question..

2007-06-18 Thread Simon Hooper
Hi Luke, * On 17/06/07, Luke Paireepinart wrote: > a more expanded version that accounts for either list being the longer > one, or both being the same length, would be: > > >>> if len(t) > len(l): x = len(t) > else: x = len(l) > >>> print [(l[i%len(l)],t[i%len(t)]) for i in range(x)] > [(1, '

Re: [Tutor] iterating over a sequence question..

2007-06-17 Thread David Heiser
nb) x = 10 print [(a[i%na], b[i%nb]) for i in range(x)], "- modulus (extended)" print print "===" This mailing list is great. Thanks to all the experienced Python coders who offer various solutions to the questions, and to all the beginners who ask them.

Re: [Tutor] iterating over a sequence question..

2007-06-17 Thread Reed O'Brien
On Jun 17, 2007, at 3:44 AM, John Fouhy wrote: > On 17/06/07, Iyer <[EMAIL PROTECTED]> wrote: >> >> say, if I have a list l = [1,2,3,5] >> >> and another tuple t = ('r', 'g', 'b') >> >> Suppose I iterate over list l, and t at the same time, if I use >> the zip >> function as in zip(l,t) , I wil

Re: [Tutor] iterating over a sequence question..

2007-06-17 Thread Alan Gauld
"Luke Paireepinart" <[EMAIL PROTECTED]> wrote > The first thing that occurred to me was just to use a modulus to > index > into the second, shorter list. That was the first thing that occured to me too but when I tried it I couldn't get it to work... > >>> l = [1,2,3,4,5] > >>> t = ('r','g','b

Re: [Tutor] iterating over a sequence question..

2007-06-17 Thread Luke Paireepinart
Alan Gauld wrote: > "Iyer" <[EMAIL PROTECTED]> wrote > > >> Any pythonic way to iterate over a sequence, while iterating >> over another shorter sequence continously >> The first thing that occurred to me was just to use a modulus to index into the second, shorter list. >>> l = [1,2,3,4

Re: [Tutor] iterating over a sequence question..

2007-06-17 Thread Alan Gauld
"Iyer" <[EMAIL PROTECTED]> wrote > Any pythonic way to iterate over a sequence, while iterating > over another shorter sequence continously I don;t know how pythonic it is, but I'd do it thus: >>> a = (1, 2, 3, 4) >>> b = ('a', 'b', 'c') >>> n = len(a)/len(b) + 1 >>> t = map(None,a,b*n)[:len(

Re: [Tutor] iterating over a sequence question..

2007-06-17 Thread John Fouhy
On 17/06/07, Iyer <[EMAIL PROTECTED]> wrote: > > say, if I have a list l = [1,2,3,5] > > and another tuple t = ('r', 'g', 'b') > > Suppose I iterate over list l, and t at the same time, if I use the zip > function as in zip(l,t) , I will not be able to cover elements 3 and 5 in > list l > > >>> l =