''.join(map(str, [1,2,3,4] ))
map(str, array)equivalent [str(x) for x in array], therefore map(str, [1,2,3,4])returns ['1', '2', '3', '4'].s.join(a)combines all the elements in a sequence ausing a string s, for example,
>>> ','.join(['foo', 'bar', '', 'baz'])
'foo,bar,,baz'
Please note that .joincan only join sequences of lines. It will not call strautomatically.
>>> ''.join([1,2,3,4])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: sequence item 0: expected string, int found
Therefore, first you need to first mapall the elements in a row.
source
share