I need to change parameters outside the loop and continue iteration after specific condition is met.
For example, I have list of pizzas and as list of strings. I have list of sauce packs whci should be switched after condition is met. If there is a condition 'sauce_error' in string, I need to switch to another sauce pack from list of sauce packs and continue iteration using next sauce pack.
#list of sauce packs
saucePacks = ['sauce_pack1', 'sauce_pack2', 'sauce_pack3', 'sauce_pack4']
index = 0
saucePack = saucePacks[index]
#list of pizzas
pizzas = ['pizza1', 'pizza2', 'pizza3_sauce_error', 'pizza4', 'pizza5']
#iterating over strings
for pizza in pizzas:
if 'sauce_error' in pizza:
index = index+1 #need to switch sauce pack if substring in string
print(saucePack, pizza)
else:
print(saucePack, pizza)
sauce pack should be switched to the next from list when 'sauce_error' occures in 'pizza' string.
desired output:
sauce_pack1 pizza1
sauce_pack1 pizza2
sauce_pack2 pizza3_sauce_error
sauce_pack2 pizza4
sauce_pack2 pizza5