This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano
Recipients eric.smith, josh.r, kj, rhettinger, samuelmarks, steven.daprano
Date 2020-12-21.07:49:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1608536984.15.0.71838839952.issue42699@roundup.psfhosted.org>
In-reply-to
Content
By the way, it is almost always wrong to write "k for k in iterable" when you can just write "iterable" or "list(iterable)".

Here are some micro-benchmarks:


[steve ~]$ python3.9 -m timeit -s "from string import ascii_letters" "''.join(k for k in ascii_letters)"
100000 loops, best of 5: 2.3 usec per loop

[steve ~]$ python3.9 -m timeit -s "from string import ascii_letters" "''.join([k for k in ascii_letters])"
200000 loops, best of 5: 1.57 usec per loop

[steve ~]$ python3.9 -m timeit -s "from string import ascii_letters" "''.join(list(ascii_letters))"
500000 loops, best of 5: 749 nsec per loop

[steve ~]$ python3.9 -m timeit -s "from string import ascii_letters" "''.join(ascii_letters)"
500000 loops, best of 5: 737 nsec per loop
History
Date User Action Args
2020-12-21 07:49:44steven.dapranosetrecipients: + steven.daprano, rhettinger, eric.smith, josh.r, samuelmarks, kj
2020-12-21 07:49:44steven.dapranosetmessageid: <1608536984.15.0.71838839952.issue42699@roundup.psfhosted.org>
2020-12-21 07:49:44steven.dapranolinkissue42699 messages
2020-12-21 07:49:44steven.dapranocreate