Skip to content

Commit d93fac5

Browse files
authored
Create reverseString.py
Python3 program to print reverse of words in a string.
1 parent ba926a0 commit d93fac5

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

reverseString.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Python3 program to print reverse of words in a string.
2+
3+
def wordReverse(str):
4+
i = len(str)-1
5+
start = end = i+1
6+
result = ''
7+
8+
while i>=0:
9+
if str[i] == ' ':
10+
start = i+1
11+
while start!= end:
12+
result += str[start]
13+
start+=1
14+
result+=' '
15+
end = i
16+
i-=1
17+
start = 0
18+
while start!=end:
19+
result+=str[start]
20+
start+=1
21+
return result
22+
23+
# Driver Code
24+
str = 'I AM A GENIUS'
25+
print(wordReverse(str))

0 commit comments

Comments
 (0)