Andrew Barnert via Python-ideas wrote:
Someone earlier in this thread said we could optimize calling split on a string literal, just as we can and do optimize iterating over a list literal in a for statement.
The counter argument—which I thought you were adding onto—is that this would be bad because it would make people write bad code for older/alternative Pythons.
There's a precedent for this kind of thing -- there's an optimisation for repeatedly concatenating onto a string in some circumstances, even though building a list and joining it is recommended if you want guaranteed good performance. So the fact that it wouldn't apply to all versions and implementations of Python shouldn't really matter.
I'm not sure how much it would really help, though. Lists being mutable, it would have to build a new list every time, unless it was also being used in a context where a tuple could be substituted, making it a doubly special case. I question whether there are many examples of such cases in the wild.