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

Ryan Gonzalez rymg19 at gmail.com
Tue Sep 29 00:23:27 CEST 2015


import re
parts = re.split(':|(-->)|,', '00:02:34...')



On Mon, Sep 28, 2015 at 5:10 PM, Niilos <niilos at gmx.com> wrote:

> 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.
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>



-- 
Ryan
[ERROR]: Your autotools build scripts are 200 lines longer than your
program. Something’s wrong.
http://kirbyfan64.github.io/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150928/e75d6dc3/attachment.html>


More information about the Python-ideas mailing list