3 ms·
With regards to the join and capitalize examples, once you consider the existence of the string module, the current way actually does make more sense. Capitali
by rflrob 16y ago
With regards to the join and capitalize examples, once you consider the existence of the string module, the current way actually does make more sense.
Capitalizing things only makes sense on a string. Having a builtin function that could capitalize any input doesn't work, so it's better to explicitly make it clear that it's a string related function. If, for some reason, you're allergic to list comprehensions, you could always do map(lambda s: s.capitalize(), strlist).
Similarly, the string module has a join function, whose definition is: return sep.join(words). The standard ''.join() is unfortunate and unobvious to the newcomer, but it's idiomatic, and there probably are unusual cases where calling a non-method join doesn't work.
- djacobs 16y agoYou could always do map(lambda s: s.capitalize(), strlist) That I could, and in fact, I do give an example like that in the accompanying analysis article [1]. However, it's not simple as Ruby. This is a comparison, after all. The two essays I've written are essentially describing what is natural in each language, not what is strictly possible. [1] http://allthingsprogress.com/posts/the-ugliness-of-python http://allthingsprogress.com/posts/the-ugliness-of-python