flâneur — a map of the web's best reading

Python Gotcha: Join vs Concat · Ponderings of an Andy

andrewwegner.com · 643 words · saved by 1 readers

Append 100,000 strings together using join or concat - Which is faster?

Article Contents The Problem Results What's happening here? What are the implications of this? The Problem ¶ Here's a somewhat contrived example to demonstrate a problem. I need to create a string with the word word 100,000 times. What's the fastest way to generate this string? I could use string concatenation (simply + the strings to one another). I could join a list with 100,000 items. My proposed code for this example is below def concat_string ( word : str , iterations : int = 100000 ) -> str : final_string = "" for i in range ( iterations ) : final_string += word return final_string def j

Explore this link on the map →

related reading