Reputation: 654
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"]
Upvotes: 15
Views: 6035
Reputation: 6785
Use splitlines()
, passing keepends=True
:
"amount\nexceeds".splitlines(keepends=True)
gives you:
["amount\n", "exceeds"]
Upvotes: 25