> On 2018 Mar 4 , at 12:59 p, Andrés Delfino <[email protected]> wrote:
>
> Hi!
>
> I was thinking: perhaps it would be nice to be able to quicky split a string,
> do some slicing, and then obtaining the joined string back.
>
> Say we have the string: "docs.python.org", and we want to change "docs" to
> "wiki". Of course, there are a ton of simpler ways to solve this particular
> need, but perhaps str could have something like this:
>
> spam = "docs.python.org"
> eggs = "wiki." + spam['.'][1:]
> print(eggs) #wiki.python.org
-1. I see no compelling reason to overload __getitem__ to provide a synonym for
the split method.
eggs = "wiki." + spam.split('.')[1:]
Besides, you can already make such replacements more efficiently with
eggs = spam.replace('docs', 'wiki')
or, for more complex replacements,
eggs = re.sub('^docs', 'wiki', spam)
--
Clint
_______________________________________________
Python-ideas mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/