15

Is there a way to split a string containing a newline character into a list of strings where the newline character has been retained, eg.

"amount\nexceeds"

would produce

["amount\n", "exceeds"]
0

1 Answer 1

25

Use splitlines(), passing keepends=True:

"amount\nexceeds".splitlines(keepends=True)

gives you:

["amount\n", "exceeds"]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.