Filed under

Strings

Joining strings in Python

There is already a lot of good material to read about performance. Therefore, it is best to use the following method: >>> print ' '.join(['The', 'fox', 'jumped', 'over', 'the', 'dog.']) The fox jumped over the dog. Perfect. We have very fast string contatenation that even allows us to choose separator. Now, here is the problem: >>> print ', '.join(['apples', 'oranges', '', 'cocos']) apples, oranges, , cocos So, if we dynamically generate string and we have a separator for a reason, we do not want this to happen. This is basically the idea:

Read article