Robert Kern <[EMAIL PROTECTED]> writes: > 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'] > You could use regular expressions as Jason Stitt mentions, or you could > replace '_' with ' ' and then split. > > In [2]: mystr = 'this_NP is_VL funny_JJ' > > In [3]: mystr.replace('_', ' ').split() > Out[3]: ['this', 'NP', 'is', 'VL', 'funny', 'JJ']
A third alternative is to split once, then split the substrings a second time and stitch the results back together: >>> sum([x.split('_') for x in mystr.split()], []) ['this', 'NP', 'is', 'VL', 'funny', 'JJ'] Which is probably slow. To bad extend doesn't take multiple arguments. <mike -- Mike Meyer <[EMAIL PROTECTED]> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list