Here's a transcript of what I want to do. It currently fails in both Python 2.7 and 3.4:
>>> a = [3,4,5]
>>> ','.join(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: sequence item 0: expected string, int found
This works, but is clumsy and potentially inefficient:
>>> ','.join(map(str, a))
'3,4,5'
My question is, does anything prevent us from enhancing Python to support str.join()
on non-string iterables (so long as they are convertible to strings, e.g. by str()
)? I looked for a PEP about this but didn't find any.