[Python-ideas] list as parameter for the split function
Niilos
niilos at gmx.com
Tue Sep 29 00:10:34 CEST 2015
Hello everyone,
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.
I imagined the split function with an iterator as parameter. The string
would be split each time its substring is in the iterator.
Here is the syntax I considered for this :
>>> '00:02:34,452 --> 00:02:37,927'.split([ ':', ' --> ', ',' ])
['00', '02', '34', '452', '00', '02', '37', '927']
Is it a relevant idea ? What do you think about it ?
Regards,
Niilos.
More information about the Python-ideas
mailing list