Problem splitting a string

SPE - Stani's Python Editor at
Sat Oct 15 12:47:21 CEST 2005

Use re.split, as this is the fastest and cleanest way.
However, iff you have to split a lot of strings, the best is:

import re
delimiters = re.compile('_| ')

def split(x):
  return delimiters.split(x)

>>> split('this_NP is_VL funny_JJ')
['this', 'NP', 'is', 'VL', 'funny', 'JJ']

SPE - Stani's Python Editor

More information about the Python-list mailing list