Simple question to split

Dan Lenski dlenski at gmail.com
Thu Nov 9 17:55:41 EST 2006


Yep, use regular expressions!  For example, use the regular expression
r',|\s+' to split on either (a) any amount of whitespace or (b) a
single comma.  Try this:

import re
a='1,2,3,4,5 6 7,3,4'
print re.split(r',|\s+*', a)

Matthias Winterland wrote:
> Hi,
>
> I have a simple question. When I read in a string like:
> a='1,2,3,4,5 6 7,3,4', can I get the list l=[1,2,3,4,5,6,7,3,4] with a
> single split-call?
> 
> Thx,
> Matthias




More information about the Python-list mailing list