Re: Change first occurrence of character x in a string - how?

2021-02-15 Thread rust buckett
Grant Edwards wrote: > On 2021-02-14, Mr Flibble wrote: >> On 14/02/2021 21:14, Chris Green wrote: >>> What's the easiest way to change the first occurrence of a specified >>> character in a string? >> >> By using a grown up (i.e. non-toy) programming language. > > > > [gotta love slrn's scori

Re: Change first occurrence of character x in a string - how?

2021-02-15 Thread Grant Edwards
On 2021-02-14, Mr Flibble wrote: > On 14/02/2021 21:14, Chris Green wrote: >> What's the easiest way to change the first occurrence of a specified >> character in a string? > > By using a grown up (i.e. non-toy) programming language. [gotta love slrn's scoring feature...] -- https://mail.pyth

Re: Change first occurrence of character x in a string - how?

2021-02-14 Thread Mr Flibble
On 14/02/2021 21:14, Chris Green wrote: What's the easiest way to change the first occurrence of a specified character in a string? By using a grown up (i.e. non-toy) programming language. /Flibble -- 😎 -- https://mail.python.org/mailman/listinfo/python-list

Re: Change first occurrence of character x in a string - how?

2021-02-14 Thread Chris Green
MRAB wrote: > On 2021-02-14 21:14, Chris Green wrote: > > What's the easiest way to change the first occurrence of a specified > > character in a string? > > > > E.g. I want to change linux-raid.vger.kernel.org to > > linux-r...@vger.kernel.org, it's a fairly general requirement of > > needing to

Re: Change first occurrence of character x in a string - how?

2021-02-14 Thread Chris Green
Gary Herron wrote: > > On 2/14/21 1:14 PM, c...@isbd.net wrote: > > What's the easiest way to change the first occurrence of a specified > > character in a string? > > > > E.g. I want to change linux-raid.vger.kernel.org to > > linux-r...@vger.kernel.org, it's a fairly general requirement of > >

Re: Change first occurrence of character x in a string - how?

2021-02-14 Thread Gary Herron
The string type has a replace function that does what you want. Except you can't change a string -- they are immutable -- so this creates a new string. >>> s = 'linux-raid.vger.kernel.org' >>> new_s = s.replace('.', '@', 1) >>> new_s 'linux-r...@vger.kernel.org' On 2/14/21 1:14 PM, c...@isb

Re: Change first occurrence of character x in a string - how?

2021-02-14 Thread Ned Batchelder
with_at = with_dots.replace(".", "@", 1) https://docs.python.org/3/library/stdtypes.html#str.replace --Ned. On Sunday, February 14, 2021 at 4:18:22 PM UTC-5, Chris Green wrote: > What's the easiest way to change the first occurrence of a specified > character in a string? > > E.g. I want to c

Re: Change first occurrence of character x in a string - how?

2021-02-14 Thread MRAB
On 2021-02-14 21:14, Chris Green wrote: What's the easiest way to change the first occurrence of a specified character in a string? E.g. I want to change linux-raid.vger.kernel.org to linux-r...@vger.kernel.org, it's a fairly general requirement of needing to change '.' to '@'. Alternatively is

Re: Change first occurrence of character x in a string - how?

2021-02-14 Thread Dan Stromberg
Check out re.sub's "count" parameter. https://stackoverflow.com/questions/3951660/how-to-replace-the-first-occurrence-of-a-regular-expression-in-python On Sun, Feb 14, 2021 at 1:20 PM Chris Green wrote: > What's the easiest way to change the first occurrence of a specified > character in a stri

Change first occurrence of character x in a string - how?

2021-02-14 Thread Chris Green
What's the easiest way to change the first occurrence of a specified character in a string? E.g. I want to change linux-raid.vger.kernel.org to linux-r...@vger.kernel.org, it's a fairly general requirement of needing to change '.' to '@'. Alternatively is there an RE 'match' function that would t