
On Sun, 8 Jan 2023 at 03:44, Steven D'Aprano <steve@pearwood.info> wrote:
Keep it nice and simple: provided with multiple separators, `partition` will split the string on the first separator found in the source string.
In other words, `source.partition(a, b, c, d)` will split on a /or/ b /or/ c /or/ d, whichever comes first on the left.
Thanks - that's a valid and similar proposal -- partition-by-any-of -- although it's not the suggestion that I had in mind. Roughly speaking, the goal I had in mind was to take an input that contains well-defined delimiters in a known order and to produce a sequence of partitions (and separating delimiters) from that input. (you and dn have also indirectly highlighted a potential problem with the partitioning algorithm: how would "foo?a=b&c" partition when using 'str.partition("?", "#")'? would it return a tuple of length five?)