re. help needed :(
Dan Bishop
danb_83 at yahoo.com
Fri Feb 22 19:22:42 EST 2002
"G. Willoughby" <sab at NOSPAM.freeuk.com> wrote in message news:<a56838$qb8$1 at newsg4.svr.pol.co.uk>...
> Hi,
> Im trying to replace the single word "lamb" and the word lamb followed
> by any punctuation in this string:
>
> x="Mary had a little lamb called lamb, but didn't like the lamb's mood"
>
> i want to replace all of the single words "lamb[punctuation]" but not the
> word "lamb's" to achieve this:
>
> x="Mary had a little pig called pig, but didn't like the lamb's mood"
>
> any help with be greatly appreiciated!
Here's one way:
x = x.replace("lamb's", "XspamX").replace("lamb", "pig").replace("XspamX", "lamb's")
More information about the Python-list
mailing list