[Tutor] Parsing string with variable length delimiter?
kent_johnson at skillsoft.com
Tue Sep 7 18:10:26 CEST 2004
If you use string.split() with no arguments, it will treat runs of
whitespace as a single separator. This is different behavior from
string.split(' '), which treats each individual space as a separator:
>>> 'a b c'.split()
['a', 'b', 'c']
>>> 'a b c'.split(' ')
['a', '', 'b', '', '', '', 'c']
At 04:00 PM 9/7/2004 +0000, Jeffrey F. Bloss wrote:
>In general, what's the "best" way to split() a series of strings such as...
>TEXT MORETEXT SOMEMORETEXT TEXT
>MORETEXT TEXT MORETEXT SOMEMORETEXT
>Text field lengths are variable as are numbers of delimiter characters.
>mystring.split(' ') yields a list including each individual space. Would
>it be best to parse that list and reject any spaces, or is there a regex
>way to modify the behavior of the .split() method? Or another method all
>Thanks in advance!
>Tutor maillist - Tutor at python.org
More information about the Tutor