Skip to content

Instantly share code, notes, and snippets.

@kaecy
Created July 3, 2022 20:25
Show Gist options
  • Save kaecy/1d6ff268f966fbce7e92d54a5e19ac26 to your computer and use it in GitHub Desktop.
Save kaecy/1d6ff268f966fbce7e92d54a5e19ac26 to your computer and use it in GitHub Desktop.
from string import whitespace
def rstrip(str):
i = len(str)
if i != 0:
while str[i - 1] in whitespace and (i := i - 1):
pass
return str[:i]
def lstrip(str):
i = 0
ei = len(str)
if ei != 0:
while str[i] in whitespace and (i := i + 1) != ei:
pass
return str[i:]
def strip(str):
ei = len(str)
i1 = 0
i2 = ei
if ei != 0:
while str[i1] in whitespace and (i1 := i1 + 1) != ei:
pass
while str[i2 - 1] in whitespace and (i2 := i2 - 1):
pass
return str[i1:i2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment