s.split() on multiple separators
mrkafk at gmail.com
mrkafk at gmail.com
Sun Sep 30 15:07:15 EDT 2007
> > ['ab', 'd', '', 'ab', '', '']
>
> Given your original string, I'm not sure how that would be the
> expected result of "split c on the characters in dels".
Oops, the inner loop should be:
for i in xrange(0,len(c)):
Now it works.
> >>> c=' abcde abc cba fdsa bcd '
> >>> import re
> >>> r = re.compile('[ce ]')
> >>> r.split(c)
> ['', 'ab', 'd', '', 'ab', '', '', 'ba', 'fdsa', 'b', 'd', '']
>
> given that a regexp object has a split() method.
That's probably optimum solution. Thanks!
Regards,
Marcin
More information about the Python-list
mailing list