Problem splitting a string

Erik Max Francis max at alcyone.com
Sat Oct 15 00:59:51 EDT 2005


Anthony Liu wrote:

> 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.

Use re.split:

 >>> re.split('_| ', s)
['this', 'NP', 'is', 'VL', 'funny', 'JJ']

-- 
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   To love without criticism is to be betrayed.
   -- Djuna Barnes



More information about the Python-list mailing list