How to join string professionally in Python
Python provides string module for manipulating given string efficiently including string.join
. On the other hand, each string object has join
method to act like the separator of given strings. However, I have just found another form of the join in Cookie.py
in Python 2.5. For example, below codes are similar.
string.join(['a','b','c'],' ') ' '.join(['a','b','c'])
It would be more readable to define function as follow.
_nulljoin = ''.join _semispacejoin = '; '.join _spacejoin = ' '.join
So the use above example should be changed.
_spacejoin(['a','b','c'])
- sugree's blog
- 3093 reads
Post new comment