Logo

Programming-Idioms

History of Idiom 296 > diff from v9 to v10

Edit summary for version 10 by Oldboy:
New Python implementation by user [Oldboy]

Version 9

2022-02-18, 13:37:21

Version 10

2022-02-20, 09:17:32

Idiom #296 Replace last occurrence of substring

Assign to x2 the value of string x with the last occurrence of y replaced by z.
If y is not contained in x, then x2 has the same value as x.

Idiom #296 Replace last occurrence of substring

Assign to x2 the value of string x with the last occurrence of y replaced by z.
If y is not contained in x, then x2 has the same value as x.

Variables
x2,x,y,z
Variables
x2,x,y,z
Extra Keywords
substring substitute
Extra Keywords
substring substitute
Code
x2 = z.join(x.rsplit(y, 1))