[Python-ideas] Add list.join() please

Brendan Barnwell brenbarn at brenbarn.net
Tue Jan 29 21:56:54 EST 2019


On 2019-01-29 15:38, Greg Ewing wrote:
> Brendan Barnwell wrote:
>>     Personally what I find is perverse is that .join is a method of
>> strings but does NOT call str() on the items to be joined.
>
> Neither do most other string methods:
>
>   >>> s = "hovercraft"
>   >>> s.count(42)
> Traceback (most recent call last):
>     File "<stdin>", line 1, in <module>
> TypeError: Can't convert 'int' object to str implicitly
>
> Why should join() be any different?

	Oh please.  Because it also RETURNS a string.  Of course count won't 
return a string, it returns a count.  But str.join is for "I want to 
join these items into a single string separated by this delimiter".  If 
the output is to a be a string obtained by combining other items, there 
is nothing lost by converting them to strings.

-- 
Brendan Barnwell
"Do not follow where the path may lead.  Go, instead, where there is no 
path, and leave a trail."
    --author unknown


More information about the Python-ideas mailing list