r/pythonhelp • u/IcyIceLidocain • Aug 01 '21
how to remove uneseccary lines form a a string?
say i have a string that looks like this:
"hi hi hi
hi hi hi"
And i want to chop off the bottom row hi hi hi so it looks like just this:
"hi hi hi"
3
Upvotes
4
u/MrPhungx Aug 01 '21
I'm pretty sure there are a lot of ways to do so. Here are two
It finds the Index of the first new line and prints everything Up to that position.
This splits the string at all new line chars and simply prints the first one