3 ms·
Similarly weirdly, the string join method really confuses me: ''.join([1, 2, 3])
by FuzzyDunlop 14y ago
Similarly weirdly, the string join method really confuses me:
''.join([1, 2, 3])
- eru 14y agoThat actually makes sense. Because the joining is something that a string knows how to do. Why should arbitrary lists know about string manipulation? By the way, your example has an error, since you can't join a list of numbers. You can only join lists of strings. I.e. ' '.join("Hello", "World")
- btbuilder 14y agoIt seems strange at first but now it feels pretty natural. The alternatives might be to have a new global function (like len) or to have every possible iterator type have join (which sounds complicated).
- jbester 14y agoIn python 1.X it was a function under the string module. This is maintained in 2.x but goes away in 3.x. string.join(['1','2','3'], ' ') == ' '.join(['1','2','3'])