Hello friends,
I am trying to reverse the words present in the string(for eg. I am a student output:student a am I) . I have reference code but i did not understand the exact working of code. can anyone please explain me the working of the code. I am the beginner in the coding.
Here is my code :
I am trying to reverse the words present in the string(for eg. I am a student output:student a am I) . I have reference code but i did not understand the exact working of code. can anyone please explain me the working of the code. I am the beginner in the coding.
Here is my code :
def wordReverse(str): i = len(str)-1 start = end = i+1 result = '' while i>=0: if str[i] == ' ': start = i+1 while start!= end: result += str[start] start+=1 result+=' ' end = i i-=1 start = 0 while start!=end: result+=str[start] start+=1 return result # Driver Code str = 'I AM A GEEK' print(wordReverse(str))