Re: [Tutor] STRING PROC
wrote a.partition('<') ('', '<', 'NAME') Ooh! A new string method for me. I've never notioced partition before. Thanks for posting. Alan G. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] STRING PROC
You can also try this >>> a = '>> a '>> a.partition('<') ('', '<', 'NAME') >>> splitstring = a.partition('<') >>> splitstring ('', '<', 'NAME') >>> splitstring[0] '' >>> splitstring[1] '<' >>> splitstring[2] 'NAME' I guess you can use this tuple. Hope this helps. Thanks and Regards, Sumod On Fri, May 20, 2011 at 6:42 PM, Spyros Charonis wrote: > Hello List, > > 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 > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > -- http://spawgi.wordpress.com We can do it and do it better. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] STRING PROC
"Spyros Charonis" 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
[Tutor] STRING PROC
Hello List, 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 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor