Specifically, I have two lists of strings that I’d like to combine into a string where each line is the next two strings from the lists, separated by spaces:
a = ['foo1', 'foo2', 'foo3']
b = ['bar1', 'bar2', 'bar3']
I want a function combine_to_lines() that would return:
"""foo1 bar1
foo2 bar2
foo3 bar3"""
I admit I’ve already solved this problem, so I’m going to post the answer. But perhaps someone else has a better one or sees a flaw in mine.
Update: I over-simplified my example above. In my real-world problem the lines were formatted in a more complicated manner that required the tuples returned from zip() to be unpacked. But kudos to mhawke for coming up to the simplest solution to this example.
It’s not necessary to unpack and repack the tuples returned by zip: