Python string list to string
I am doing something painfuly simple, and rather than looping over the list, and += everything, I was wondering if there was a "sleezier" way to do it.
Simple concept I have something like:
some_string_array = [ "s", "t", "a", "c", "k", " ", "o", "v", "e", "r", "f", "l", "o","w" ]
some_string = some_string_array.--sleezy built-in flatten--()
print(some_string)
And the resul开发者_如何学JAVAt would be simply stack overflow
I am sure it is painfuly simple, but I couldn't find a good way to search for this online.
Thanks.
Just use
"".join(some_string_array)
even more sleazier:
reduce(lambda a,b:a+b,some_string_array)
http://docs.python.org/library/functions.html#reduce
精彩评论