46 ms·
This seems like it would be great for a list comprehension. I believe the main appeal to using comprehensions is that it speeds up the iteration process at run
by no_wizard 9y ago
This seems like it would be great for a list comprehension.
I believe the main appeal to using comprehensions is that it speeds up the iteration process at run time so wouldn't a list comprehension be just as useful here if not more so then?.
You could also use the functools and itertools library for really fast iterations, possibly, depending on what it is you are trying to achieve.
If you are specifically talking lists (arrays) why not use Deque? It is set matched and python saves run time by automatically knowing each value will be a finite forward sequence
- innocenat 9y agoBut would that be faster than numpy? numpy in typical setup would use SIMD or other math kernel (mkl, blas, etc).
- lima 9y agoIt wouldn't. Pure Python code is never going to out-perform a low-level optimized C library. Especially not when comparing iterative vs vectorized code.
- no_wizard 9y agoOh no of course not. Sorry I must have missed something here. I was speaking specifically of iterating over/with values. Numpy is optimized for this kind of thing. Though you can help yourself out and make sure you python code is also optimized by using comprehensions and itertools I would suppose