I am an old dog who used BASIC > 30 years ago. I have run into this scenario in using for loops in python before, but I picked this illustration for my concern about loops:
I would like to parse a long string which includes words in double quotes separated by commas. I can ignore double quotes, but I want the loop to advance here. I don't feel like this is very elegant. I am carrying unnecessary looping baggage. Should I do away with the loop altogether, in which case, is slicing the preferred method, and is there a general rule to apply to the question of using loops or not?
"""
data is the str-type variable
line, despite the name, seems to pull out just one character at a time
(which is not relevant except to confirm my naïveté in python)
"""
for line in data:
if line.endswith('"'):
x = True # doing nothing but advancing the for loop
elif line.endswith(','):
# do something at a comma
else:
# continue the parsing
Edit Example string:
"All","the","world","'s","a","stage","And","all","the","men","and","women","merely","players"