[Tutor] Splitting by word boundaries

David Rock david at graniteweb.com
Thu Aug 14 21:44:08 EDT 2003


* Jonathan Hayward http://JonathansCorner.com <jonathan.hayward at pobox.com> [2003-08-14 18:28]:
> I'm trying to split along word boundaries, but when I pass e.g. "a b c 
> d" to:
> 
>        text_tokens = re.split("\b", text)
> 
> But the re.split seems to return a list with only one string, the uncut 
> text. Comments?

If you are splitting by word boundaries, why not just use string.split?
The default split is whitespace:
	import string
	test = 'a b c d'
	split_test = string.split( test )

-- 
David Rock
david at graniteweb.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20030814/c1dcdd51/attachment.bin


More information about the Tutor mailing list