Reverse function


#1



Reverse Function.
Here is my solition:


def reverse(text):
a=''
for i in range(1,len(text)+1):
a+=text[-i]
return a


Is there any better way?


Replace this line with your code.


#2

better in what way? Readability? Performance?

your program could improve on performance, strings are immutable in python, so here:

a+=text[-i]

a new string is created with the combined result, this takes more memory then when a list is used


#3

Thanks.
So the better way is creating list and join it in string?


#4

performance wise that will be a improved, yes


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.