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

Andrew Barnert abarnert at yahoo.com
Tue Sep 29 00:45:11 CEST 2015

On Sep 28, 2015, at 15:10, 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.

As a side note, a list is not an Iterator. It's an iterable, but an Iterator is a special kind of iterable that only allows one pass, which is definitely not what you want here. In fact, what you probably want is a sequence (or maybe just a container, since the only thing you want to do is test "in"). 

Also, the way you've defined this ("each time its substring is in the iterator") is either ambiguous, or inherently expensive, depending on how you read it. And once you work out what you actually mean, it's hard to express it better than as a regular expression, which is why half a dozen people jumped to that answer.

More information about the Python-ideas mailing list