Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
See more:
Java
string reverse(string word){
string temp = "";
if(word.length() > 1){
temp = word.substr(word.length()-1, word.length());
temp += reverse(word.substr(0, word.length()-1));
}
else
return word;
return temp;


so far I've got...

Python
def reverse(word):
temp = ''
if word.len() > 1:
Posted
Updated 1-Nov-15 5:48am
v2
Comments
PIEBALDconsult 1-Nov-15 11:49am    
I suggest you first rewrite the Java implementation because it's awful. Really really awful; it must have been written by a rank amateur. Or ignore that particular Java code and start fresh.
You might also simply do an Internet search for "python string reverse".

1 solution

Just a one line code to reverse the string in python. Read the documentation[^]
Python
s[::-1]
'dcba'
# where s was 'abcd' and then it is voila

Or without using it:
def reverse(test):
    n = len(test)
    x=""
    for i in range(n-1,-1,-1):
        x += test[i]
    return x

Though you can find certain help on this thread[^].

-KR
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 1-Nov-15 16:27pm    
!alioV
a 5.
—SA
Krunal Rohit 1-Nov-15 23:19pm    
:laugh:
Thanks.

-KR

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900