[Tutor] updating step size while in loop

Alan Gauld alan.gauld at btinternet.com
Tue Jul 10 09:46:56 CEST 2012


On 09/07/12 22:59, Abhishek Pratap wrote:
>
> I want to know whether it is possible for dynamically update the step
> size in xrange  or someother slick way.
>
> Here is what I am trying to do, if during a loop I find the x in list
> I want to skip next #n iterations.

You could use the next() method of the iterator. But you need to make 
the iterator explicit:

it = iter(xrange(start, stop,step))
for n in it:
     if n in mylist:
        for i in range(jump_size):
             it.next()


HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/





More information about the Tutor mailing list