Hello, I am using a for loop to iterate through an array and need to assign each iteration to a new variable, such as
but instead of printing i, I want the for lopp to assign each iteration to a unique variable, so that when the for loop completes
I will use these variables later on in the script. I will not always know how many items are in the array and need the script to generate a new variable for each iteration. Any ideas?
Code:
arr = ['bread', 'milk', 'cheese'] for i in arr: print i
Code:
var1 = 'bread' var2 = 'milk' var3 = 'cheese'
Comment