James Addison via Python-ideas writes:
> On Sun, 8 Jan 2023 at 08:32, Stephen J. Turnbull
> wrote:
> Trying to avoid the usual discussions about permissive parsing /
> supporting various implementations in-the-wild: long-term, the least
> ambiguous and most computationally-efficient environm
Steven D'Aprano writes:
> I mean, if all you are doing is splitting the source by some separators
> regardless of order, surely this does the same job and is *vastly* more
> obvious?
>
> >>> re.split(r'[:;]', 'foo:bar;baz')
> ['foo', 'bar', 'baz']
"Obvious" yes, but it's also easy to inv
On 10/01/2023 01.19, James Addison wrote:
On Sun, 8 Jan 2023 at 20:20, dn wrote:
Herewith a repetition of an earlier repetition of a call for Python
examples and use-cases.
(to better justify the base-idea, which I support)
(and hence earlier illustration/question: does the sep belong wit
On Sun, 8 Jan 2023 at 20:20, dn wrote:
>
> (and hence earlier illustration/question: does the sep belong with the
> string forming the left-side of that partition, or the 'right'?)
There's no connection implied between each separator and the
partitions that surround it in the results.
In the use
On 08/01/2023 23.10, James Addison via Python-ideas wrote:
On Sun, 8 Jan 2023 at 03:44, Steven D'Aprano 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,
On 08/01/2023 17:06, James Addison wrote:
On Sun, 8 Jan 2023 at 13:20, Barry Scott wrote:
Maybe combine the ideas by allowing a tuple where a string is used.
'a=b;c'.partition('=', (':',';')) => ('a', '=', b, ';', 'c')
I like that idea - and it seems to fit neatly with the existing
partition
On Sun, 8 Jan 2023 at 08:32, Stephen J. Turnbull
wrote:
>
> Steven D'Aprano writes:
>
> > On Sat, Jan 07, 2023 at 10:48:48AM -0800, Peter Ludemann wrote:
> > > You can get almost the same result using pattern matching. For example,
> your
> > > "foo:bar;baz".partition(":", ";")
> > > can be d
On Sun, Jan 08, 2023 at 05:30:30PM +0900, Stephen J. Turnbull wrote:
> Steven D'Aprano writes:
>
> > On Sat, Jan 07, 2023 at 10:48:48AM -0800, Peter Ludemann wrote:
> > > You can get almost the same result using pattern matching. For example,
> your
> > > "foo:bar;baz".partition(":", ";")
> >
On Sun, 8 Jan 2023 at 13:20, Barry Scott wrote:
> Maybe combine the ideas by allowing a tuple where a string is used.
> 'a=b;c'.partition('=', (':',';')) => ('a', '=', b, ';', 'c')
I like that idea - and it seems to fit neatly with the existing
partition contract: the inclusion of the matched-de
> On 8 Jan 2023, at 10:10, James Addison via Python-ideas
> wrote:
>
> On Sun, 8 Jan 2023 at 03:44, Steven D'Aprano 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 othe
On Sun, 8 Jan 2023 at 03:44, Steven D'Aprano 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, whic
Steven D'Aprano writes:
> On Sat, Jan 07, 2023 at 10:48:48AM -0800, Peter Ludemann wrote:
> > You can get almost the same result using pattern matching. For example,
> > your
> > "foo:bar;baz".partition(":", ";")
> > can be done by a well-known matching idiom:
> > re.match(r'([^:]*):([^;]*)
On Sat, Jan 07, 2023 at 10:48:48AM -0800, Peter Ludemann wrote:
> You can get almost the same result using pattern matching. For example, your
> "foo:bar;baz".partition(":", ";")
> can be done by a well-known matching idiom:
> re.match(r'([^:]*):([^;]*);(.*)', 'foo:bar;baz').groups()
"Well-known"
+1 on the idea of having `partition` and `rpartition` take multiple
separators.
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
On 08/01/2023 00.56, James Addison via Python-ideas wrote:
# Feature or enhancement
The str.partition[1] method -- and similarly the bytes.partition[2] method --
is useful when dividing an input into subcomponents while returning a tuple of
deterministic length (currently 3) and potentially retai
You can get almost the same result using pattern matching. For example, your
"foo:bar;baz".partition(":", ";")
can be done by a well-known matching idiom:
re.match(r'([^:]*):([^;]*);(.*)', 'foo:bar;baz').groups()
___
Python-ideas mailing list -- python-id
16 matches
Mail list logo