[issue42699] Use `.join(k for k in g)` instead of `.join([k for k in g])`

Raymond Hettinger report at bugs.python.org
Sun Dec 20 23:37:54 EST 2020


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

Sorry Samuel, but this would be a performance degradation.  The reason is that the algorithm of str.join makes two passes over the input, so it runs faster when the input is already a list; otherwise, it would have to do the additional work of creating a list.

----------
nosy: +rhettinger
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42699>
_______________________________________


More information about the Python-bugs-list mailing list