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 afteri
.this change rangerange(4)
. end loop, , restartfor in range(4)
.
- if
- if meet conditions, continue in
range(3)
. ifi
reaches end without having add in new point, exit loop , continue rest of code.
- if meet conditions, continue in
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
Post a Comment