Click here to Skip to main content
14,495,629 members
Rate this:
Please Sign up or sign in to vote.
See more:
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));
return word;
return temp;

so far I've got...

def reverse(word):
temp = ''
if word.len() > 1:
Updated 1-Nov-15 5:48am
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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

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

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

a 5.
Krunal Rohit 1-Nov-15 23:19pm


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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100