Created
January 18, 2023 14:55
-
-
Save qwertyowmx/5ac252c951eca93b1716e067736d6b8c to your computer and use it in GitHub Desktop.
Python reverse string (slow)
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
def reverse_str(s: str): | |
accumulator_str = [] | |
index = len(s) | |
while index: | |
index -= 1 | |
accumulator_str.append(s[index]) | |
return ''.join(accumulator_str) | |
print(reverse_str("abcde")) | |
print(reverse_str("abcdef")) | |
print(reverse_str("abcdeaaa")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment