Problem splitting a string
antonyliu2002 at yahoo.com
Sat Oct 15 06:52:07 CEST 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?
Yahoo! Mail - PC Magazine Editors' Choice 2005
More information about the Python-list