Reputation: 10795
How can I get a one word school from the list ['s', 'c', 'h', 'o', 'o', 'l']?
Thanks!
Upvotes: 0
Views: 153
Reputation: 9622
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'
>>>
Upvotes: 0
Reputation: 35522
>>> l=['s', 'c', 'h', 'o', 'o', 'l']
>>> print ''.join(l)
school
Upvotes: 1
Reputation: 1207
must have been asked/answered a million times, but here it is:
''.join(['s', 'c', 'h', 'o', 'o', 'l'])
Upvotes: 2
Reputation: 42040
your_list = ['s', 'c', 'h', 'o', 'o', 'l']
new_string = "".join(your_list)
Upvotes: 1
Reputation:
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).
Upvotes: 9