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.
I'm not sure how to break the string, though.
I looked through the docs and found split() and partition(), which come
close.
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.

Here's the script in its basic form:

#!/usr/bin/python

text = raw_input("Enter text: ")
print "You entered ", text

objects = text.partition(' and')
print objects

for object in objects:        # Second Example

   print object

For example, if I run this with the input:
"Ham and cheese omelette with hasbrowns and coffee."
I get:
Ham
 and
 cheese omelette with hashbrowns and coffee.

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

Reply via email to