* David Rock <da...@graniteweb.com> [2012-08-23 15:03]: > * Jared Nielsen <nielsen.ja...@gmail.com> [2012-08-23 12:05]: > > Hi all, > > I'm new to programming and Python. > > I want to write a script that takes a string input and breaks the string at > > keywords then outputs the pieces on separate lines. > > > But split() doesn't retain the separator and partition() retains the white > > space and returns a 3-tuple which I'll have to figure out how to rejoin nor > > does it partition on subsequent instances of the separator. > > While it's true that split() doesn't retain the separator, you still > know what the separator is, right? Why not do something like: > > text = raw_input("Enter text: ") > sep = 'and' > parts = text.split(sep) > for i in parts[:-1]: > print i > print sep > print [-1]
Oops, print [-1] should have been print parts[-1] Hopefully you get the idea, though. -- David Rock da...@graniteweb.com _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor