[Python-ideas] Split, slice, join and return "syntax" for str
Steven D'Aprano
steve at pearwood.info
Sun Mar 4 18:23:49 EST 2018
On Sun, Mar 04, 2018 at 01:44:20PM -0500, Clint Hepner wrote:
> -1. I see no compelling reason to overload __getitem__ to provide a synonym for the split method.
>
> eggs = "wiki." + spam.split('.')[1:]
Fair point. Neither do I. But your next comment:
> Besides, you can already make such replacements more efficiently with
>
> eggs = spam.replace('docs', 'wiki')
is not suitable, because it assumes that the substring "docs" appears
only once in the string.
In a more realistic example, you don't know what the string contains,
only that it is delimited by dots and that you want to replace the n-th
field (whatever it contains) with "wiki".
--
Steve
More information about the Python-ideas
mailing list