for loop - Python : update the list in for-condition dynamically -
i writing piece of code scenario facing.
how update list in for-condition, , next iteration, list in for-condition updated?
eg., list = [0,1,2] in list: print list[i] if list[i] == 0: list.append(3) the entry '3' should updated in list in for-condition.
is possible update list in for-condition dynamically?
thanks in advance.
yes, if that, work. however, it's not idea, because can create confusing interactions between iteration , loop-body action. in example, add element @ end, if, instance, change element in middle, may or may not see change depending on in list when happens. (for instance, change value of element iterated past.)
also, shouldn't name variable list, shadows built-in type called list.
Comments
Post a Comment