Time complexity of string concatenation in Python [duplicate]
Yes, in your case*1 string concatenation requires all characters to be copied, this is a O(N+M) operation (where N and M are the sizes of the input strings). M appends of the same word will trend to O(M^2) time therefor. You can avoid this quadratic behaviour by using str.join(): word = ”.join(list_of_words) which only takes … Read more