Last active
July 18, 2020 19:45
-
-
Save raeq/7c93647f29cf347fe4c362653361dff7 to your computer and use it in GitHub Desktop.
Remove a character from a string at index
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def remove_by_index(original: str = "", index: int = -1) -> tuple: | |
if len(original) >= index and index >= 0: | |
return (original[:index] + original[index + 1:], original[index]) | |
else: | |
return (original, "") | |
assert remove_by_index("0123456789", 5) == ("012346789", "5") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment