I have this String:
Hello World.\n
I'm very happy today.\n\n\n\n\n
How are you?\n\n\n
Bye.
And I want to split it by two or more new lines without using any libraries. Output:
['Hello World.\n I'm very happy today','How are you?','Bye']
I have this String:
Hello World.\n
I'm very happy today.\n\n\n\n\n
How are you?\n\n\n
Bye.
And I want to split it by two or more new lines without using any libraries. Output:
['Hello World.\n I'm very happy today','How are you?','Bye']
Python's base string function split()
should work here, without the need to import anything:
inp = "Hello World.\nI'm very happy today.\n\n\n\n\nHow are you?\n\n\nBye."
terms = inp.split('\n\n')
print(terms)
This prints:
["Hello World.\nI'm very happy today.", '', '\nHow are you?', '\nBye.']