Newbie Q: efficiency of list -> string conversion

Erik Johnson ejohnso9 at earthlink.net
Mon Nov 19 20:02:00 EST 2001


I am wondering about the efficiency of converting a list of single
characters into the corresponding string. Here is a trivial example:

s = "string"
l = list(s)
l.reverse()

rv = ""
for i in xrange(len(l)):
  rv += l[i]

print rv


    This works, but in general, this seems grossly inefficient for large
lists.
This method involves creating and destroying n = len(l) different
strings objects.  I am pretty new to Python and not savvy to all the
funcitons and libraries yet - does someone know an efficient way to do
this?

Thanks in advance. :)

Sincerely,
-ej




More information about the Python-list mailing list