4 ms·
No list comprehension? I thought list comprehension were faster than loops?
by dorfsmay 10y ago
No list comprehension?
I thought list comprehension were faster than loops?
- sametmax 10y agoYes but it's still a loop in Python, which means it calls iter() then __next__() in a try/except to catch StopIteration in the end. It's a lot of overhead. tostring() or encode() will do an implicity loop in C, which will be much faster.
- ngoldbaum 10y agoList comprehensions didn't exist when this post was written.
- abecedarius 10y agoUsually a little slower, when I've timed them. (This may be out of date.) in Py3 they byte-compile into a loop in a nested function.