I have a list of tuples like this (strings are fillers ... my actual code has unknown values for them):
list = [
('one', 'two', 'one'),
('one', 'two', 'one', 'two', 'one'),
('one', 'two', 'one', 'two', 'one', 'two', 'one'...)
]
I would like to wrap every other line (in this example, two lines) in tags <strong> </strong>. This is frustrating for what I cannot do '<strong>'.join(list), because each other will not. This is the only approach I can think of, but using the flag bothers me ... and I cannot find anything else on the Google machine about this problem.
def addStrongs(tuple):
flag = False
return_string = ""
for string in tuple:
if flag :
return_string += "<strong>"
return_string += string
if flag :
return_string += "</strong>"
flag = not flag
return return_string
formatted_list = map(addStrongs, list)
Sorry if this is a mistake, I'm still new to python. Is there a better way to do this? I feel this may be useful in other areas, as well as adding to left / right quotes.
source
share