Reputation: 988
I currently try to concatenate two multiline string horizontally. For example, having two strings str_a and str_b
str_a = """This is row \nAnd this is row\nThis is the final row"""
str_b = """A\nB"""
With the print return
This is row
And this is row
This is the final row
and
A
B
The print return of the resulting string after the horizontal concatenation should look like
This is row A
And this is row B
This is the final row
Upvotes: 2
Views: 740
Reputation: 69735
Use this:
import itertools
for a, b in itertools.zip_longest(str_a.split('\n'), str_b.split('\n')):
print(a, b if b else '')
Output:
This is row A
And this is row B
This is the final row
Upvotes: 4