python equiv of perl's split?
pedro_rodriguez at club-internet.fr
Mon Jan 13 16:10:37 CET 2003
On Mon, 13 Jan 2003 15:24:39 +0100, pete-temp-12-29-2002 wrote:
> Just wondering what the 'best' way of emulating perl's split() method
> when used in the following manner:
> split /(:)/
> Basically, split the string using a colon as the separator. NOTE: the
> parens indicate that the split function should *include* the colons in
> the returned list. Thus, given the string:
> The following array (list) is returned:
> What would be the easiest way to emulate this in Python?
>>> import re
>>> re.split("(:)", "test:one:two:three")
['test', ':', 'one', ':', 'two', ':', 'three']
More information about the Python-list