"Spyros Charonis" <s.charo...@gmail.com> wrote

A quick string processing query. If I have an entry in a list such as
['>NAME\n'],
is there a way to split it into two separate lines:


NAME

Yes if you know where the linebreak will be.

s = ">NAME\n"
twolines = [s[0],s[1:]]   # list of two strings

for line in twolines; print line

or if you really just want a newline inserted:

twolines = s[0] + '\n' + s[1:]  insert newline

or use replace:

twolines = s.replace( '>' , '>\n' )

If you want more sophistication you could
use  a regex to determine the split point.

hth,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to