0

I know that concatenating two strings using the += operator makes a new copy of the old string and then concatenates the new string to that, resulting in quadratic time complexity.

This answer gives a nice time comparison between the += operation and string.join(str_list, ''). It looks like the join() method runs in linear time (correct me if I am wrong). Out of curiosity, I wanted to know how the string.join(str_list, '') method is implemented in Python since strings are immutable objects?

mhaseebmlk
  • 212
  • 2
  • 5

1 Answers1

1

It's implemented in C, so python mutability is less important. You can find the appropriate source here: unicodeobject.c

CJR
  • 3,916
  • 2
  • 10
  • 23