When we are taught
for loops, it is described something like this…
for element in iterable:
It can be any iterable, a string, a list, a tuple, a set, a dict, or an iterator such as map, filter, zip, etc.
We learned that
str.split() returns a new list, so as it appears here is also iterable, so,
for x in str.split(separator):
separator can be any character string, hence we see,
for color in sale.split('&'):
It is not necessary in this case to assign it to any variable since it is a list object, already. Nothing is keeping us from creating an intermediate variable, and then using it, but on refactoring we would eventually revert to the above.
sale_split_on_ampersand = sale.split('&') for color in sale_split_on_ampersand: