I have two arrays:
- colors - Contains color names, represented by a list type;
- string - String with some phrase, represented by a string type.
Code:
colors = ["red", "black", "blue",]
string = "Hello World"
def animate():
for i in range(len(string)):
print "{0} - {1}".format(string[i], colors[i%len(colors)])
print "Next iteration..."
#while True:
for i in range(3): # Short example loop - range(3)
animate()
Output:
H - red
e - black
l - blue
l - red
o - black
Next iteration...
H - red
e - black
...
And so on...
The goal: each new next iteration has to begin with next color i.e.
H - red # Begins with first color
e - black
l - blue
l - red
o - black
Next iteration...
H - black # Begins with second color
e - blue
...
Next iteration...
H - blue # Begins with third color
e - red
... # Next one begins again with the first.
And so on...
What ways are there to modify my code? Can it be implemented inside the animate function only? I was thinking about python generator functions (yield), but finale loop where animate() is resets generator function.