[Tutor] how to split/partition a string on keywords?

eryksun eryksun at gmail.com
Thu Aug 23 23:02:56 CEST 2012


On Thu, Aug 23, 2012 at 3:05 PM, Jared Nielsen <nielsen.jared at gmail.com> wrote:
> 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.

This is just for printing? You can use replace():

>>> text = "Ham and cheese omelette with hasbrowns and coffee."
>>> print text.replace(" and ", "\nand\n")
Ham
and
cheese omelette with hasbrowns
and
coffee.


More information about the Tutor mailing list