Skip to content

Commit 76221d1

Browse files
committed
Add new file
1 parent 576477e commit 76221d1

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

reverse.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#Write a function that takes a string and returns its reverse
2+
#without using the reversed() function.
3+
def reverse(text):
4+
rev = ""
5+
for i in range(len(text), 0, -1): #Reverse range, stepping backwards
6+
rev += text[i-1] #Appending to text backwards
7+
8+
return rev
9+
10+
print reverse("abcd")
11+
12+
# First Attempt tried to use .pop() unsuccessfully.
13+
# text = list(text)
14+
# rad = []
15+
# while len(text) > 0:
16+
# rad.append(text.pop())
17+
#
18+
# return rad
19+
# #r.append(len[text])
20+
# #print r

0 commit comments

Comments
 (0)