Hacker News new | ask | show | jobs
by FuzzyDunlop 5031 days ago
Similarly weirdly, the string join method really confuses me:

    ''.join([1, 2, 3])
3 comments

That 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")
It 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).
In 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'])