Apr-03-2022, 02:52 AM
(This post was last modified: Apr-03-2022, 02:52 AM by deanhystad.)
I am being sincere. I think it is good advice. Write code to be correct and easy to maintain. If there are performance issues, fix those when they occur. Often this will involve not writing code in Python at all, but instead using Python packages like numpy or pandas that are highly optimized and do much of their work in linked libraries. You are not going to see big changes in performance using a comprehension or map instead of a loop. They are good tools, but they don't turn Python into C. At least that is not my experience.
I use comprehensions and map and other functools because I can write a lot of function in a few lines of code. Potential performance benefits don't cross my mind. I often find a nice comprehension easier to read than a stretched out for loop.
As always, the best way to speed up code is run less code. Optimize the algorithm to get real speed gains.
I use comprehensions and map and other functools because I can write a lot of function in a few lines of code. Potential performance benefits don't cross my mind. I often find a nice comprehension easier to read than a stretched out for loop.
As always, the best way to speed up code is run less code. Optimize the algorithm to get real speed gains.