2

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 

1 Answer 1

4

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 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.