Problem splitting a string
Anthony Liu
antonyliu2002 at yahoo.com
Sat Oct 15 00:52:07 EDT 2005
I have this simple string:
mystr = 'this_NP is_VL funny_JJ'
I want to split it and give me a list as
['this', 'NP', 'is', 'VL', 'funny', 'JJ']
1. I tried mystr.split('_| '), but this gave me:
['this_NP is_VL funny_JJ']
It is not splitted at all.
2. I tried mystr.split('_'), and this gave me:
['this', 'NP is', 'VL funny', 'JJ']
in which, space is not used as a delimiter.
3. I tried mystr.split(' '), and this gave me:
['this_NP', 'is_VL', 'funny_JJ']
in which, '_' is not used as delimiter.
I think the documentation does say that the
separator/delimiter can be a string representing all
delimiters we want to use.
I do I split the string by using both ' ' and '_' as
the delimiters at once?
Thanks.
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
More information about the Python-list
mailing list