Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:

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

----------
nosy: +steven.daprano

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue42699>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to