Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions solutions/python/reverse-string/1/reverse_string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def reverse(text):
# Initialize an empty list
reversed_chars = []

# 2. Loop backward from the last index to 0
# Note: 'for' loop is correctly indented once
for i in range(len(text) - 1, -1, -1):
# 3. Append the character using the correct variable name 'text'
# Note: This line is correctly indented twice
reversed_chars.append(text[i])

# 4. Join the list of characters back into a single string
# Note: 'return' is correctly indented once
return "".join(reversed_chars)