Python: Changing the conditions of a 'for' loop -


i attempting loop through set of points, , if conditions met, add in point inbetween current point , next one. want start loop again, running on both old , new points. example:

  • for in range(3)

    • if i doesn't meet set of conditions, add in new point after i.this change range range(4). end loop, , restart for in range(4).
    • if meet conditions, continue in range(3). if i reaches end without having add in new point, exit loop , continue rest of code.

i have tried variety of methods, can't work. understanding along lines of:

b = 3 in range(b):     if (i meets conditions):         pass     else:         b = b+1         "retry entire loop new b" 

i have tried using while loop, can't see how start again @ first point, should new point added in.

i might missing simple, can't see solution this.

thanks help!

you'll need use recursive function this:

def func(l):    i, el in enumerate(l):        if (el match conditions):             l.insert(i+1, something)             return func(l)    return l   l = [1, 2, 3] result = func(l) 

or use while loop:

l = [1, 2, 3] while true:     = 0     if >= len(l):         break     if (l[i] match condition):         l.insert(i+1, something)         = 0     else:         += 1 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -