[Python-ideas] list as parameter for the split function

Paul Moore p.f.moore at gmail.com
Tue Sep 29 00:24:26 CEST 2015


On 28 September 2015 at 23:10, Niilos <niilos at gmx.com> wrote:
> I was wondering how to split a string with multiple separators.
> For instance, if I edit some subtitle file and I want the string
> '00:02:34,452 --> 00:02:37,927' to become ['00', '02', '34', '452', '00',
> '02', '37', '927'] I have to use split too much time and I didn't find a
> "clean" way to do it.

You can use re.split:

>>> re.split(r':|,| --> ', '00:02:34,452 --> 00:02:37,927')
['00', '02', '34', '452', '00', '02', '37', '927']

Paul


More information about the Python-ideas mailing list