Created
July 3, 2022 20:25
-
-
Save kaecy/1d6ff268f966fbce7e92d54a5e19ac26 to your computer and use it in GitHub Desktop.
This file contains 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
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