Problem splitting a string

SPE - Stani's Python Editor spe.stani.be at gmail.com
Sat Oct 15 06:47:21 EDT 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']

Stani
--
SPE - Stani's Python Editor http://pythonide.stani.be




More information about the Python-list mailing list