Skip to content

Feature request: replace #1

Open

Description

@endrebak
>>> "hi".replace("h", "H")
Hi

Would be neat if it could take a dict so this worked:

>>> "hi".replace({"h": "i", "i": "h"})
ih

Or a regex (see pandas.Series.str for inspiration?):

"hi".replace("h|i", "NYAN")
NYANNYAN

Activity

  1. btwael commented on Mar 25, 2020

    @btwael
    Owner

    Hello @endrebak, thank you, I will start working on this for the as soon as possible. I will check also that pandas.Series.str.

  2. kamikaze commented on Apr 7, 2020

    @kamikaze

    pervert request... how about sticking to standard string api and implementing extra stuff in a separate class/whatever? And creating a PR for Python to include your optimizations for standard string

  3. endrebak commented on Apr 7, 2020

    @endrebak
    Author

    Or the PR could improve the API too if it is backwards compatible. The second suggestion is but the third isn’t.

    This is backwards compatible:

    import re
    pat = re.compile(“h|i”)
    "hi".replace(pat, "NYAN")
    NYANNYAN
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions