[Tutor] iterating over a sequence question..

Iyer maseriyer at yahoo.com
Wed Jun 20 08:43:25 CEST 2007


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 <rabidpoobear at gmail.com> wrote: 

On 6/18/07, Simon Hooper <simon at partex.co.uk> 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 [(l[i%len(l)],t[i%len(t)]) for i in range(x)]
> [(1, 'r'), (2, 'g'), (3, 'b'), (4, 'r'), (5, 'g')]

Being the duffer that I am, I'm very pleased with myself that I came up 
with a similar solution (albeit as a function rather than a list
comprehension) :)

You do not need the if statement either,
Yeah, I never knew about the max() function!
I noticed someone else used it in one of their solutions. 
I'm pretty sure I've seen it a lot before, just didn't remember it.
-Luke



 _______________________________________________
Tutor maillist  -  Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor


 
---------------------------------
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070619/4bcb78f3/attachment.htm 


More information about the Tutor mailing list