Skip to content

Instantly share code, notes, and snippets.

@raeq
Last active July 18, 2020 19:45
Show Gist options
  • Save raeq/7c93647f29cf347fe4c362653361dff7 to your computer and use it in GitHub Desktop.
Save raeq/7c93647f29cf347fe4c362653361dff7 to your computer and use it in GitHub Desktop.
Remove a character from a string at index
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