A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2013-February/124015.html below:

[Python-Dev] Usage of += on strings in loops in stdlib

[Python-Dev] Usage of += on strings in loops in stdlib [Python-Dev] Usage of += on strings in loops in stdlibSteven D'Aprano 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[0] + array[1] + array[2] + ... + array[N]

or:

     # not an expression
     result = ""
     for s in array:
         result += s

or even:

     # currently prohibited, and not obvious
     sum(array, "")

although I will admit to a certain fondness towards

     # even less obvious than sum
     map(operator.add, array)


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=" "]).




-- 
Steven
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4