[Python-Dev] Usage of += on strings in loops in stdlib
steve at pearwood.info
Wed Feb 13 12:37:13 CET 2013
On 13/02/13 19:52, Larry Hastings wrote:
> I've always hated the "".join(array) idiom for "fast" string concatenation
>--it's ugly and it flies in the face of TOOWTDI. I think everyone should
>use "x = a + b + c + d" for string concatenation, and we should just make
> that fast.
"".join(array) is much nicer looking than:
# ridiculous and impractical for more than a few items
array + array + array + ... + array[N]
# not an expression
result = ""
for s in array:
result += s
# currently prohibited, and not obvious
although I will admit to a certain fondness towards
# even less obvious than sum
and join has been the obvious way to do repeated concatenation of many substrings since at least Python 1.5 when it was spelled "string.join(array [, sep=" "]).
More information about the Python-Dev