"how to convert a string that has newline characters in it into a list in python? " Code Answer

4

you want your_str.splitlines(), or possibly just your_str.split('n')

using a for loop -- for instructional use only:

out = []
buff = []
for c in your_str:
    if c == 'n':
        out.append(''.join(buff))
        buff = []
    else:
        buff.append(c)
else:
    if buff:
       out.append(''.join(buff))

print out
By doubleunary on January 20 2022
Only authorized users can answer the Search term. Please sign in first, or register a free account.