How can I get a one开发者_高级运维 word school from the list ['s', 'c', 'h', 'o', 'o', 'l']?
Thanks!
str.join(iterable)
Return a string which is the concatenation of the strings in the iterable iterable. A TypeError will be raised if there are any non-string values in seq, including bytes objects. The separator between elements is the string providing this method.
I.e. ''.join(parts)
As indicated in the description, this works for all iterables of strings, not just for lists of characters (single-letter strings).
must have been asked/answered a million times, but here it is:
''.join(['s', 'c', 'h', 'o', 'o', 'l'])
your_list = ['s', 'c', 'h', 'o', 'o', 'l']
new_string = "".join(your_list)
>>> l=['s', 'c', 'h', 'o', 'o', 'l']
>>> print ''.join(l)
school
Hope this would help you . Even though ''.join(['s', 'c', 'h', 'o', 'o', 'l']) works I personally love using the method shown below .. Anyway its ur call :)
>>> word
['s', 'c', 'h', 'o', 'o', 'l']
>>> reduce(lambda a,x:a+x,word)
'school'
>>>
精彩评论