DEV Community

Discussion on: Help me with points to be considered while coding to avoid execution overhead in Python

Collapse
 
rhymes profile image
rhymes

A possible one is to use lists to join long strings instead of creating many strings objects but it makes a difference only if you have massive objects or massive loops.

Example:

v = ["a", "b", "c"]
s = ““.join(v)

Instead of

v = "a"
v += "b"
v += "c"

But this doesn't really matter if you have a few strings, that's why the strategy is code first, optimizations later.

You can help yourself using tools like flake8 plus github.com/PyCQA/flake8-bugbear/bl... or a code formatter like github.com/ambv/black (clear code makes it easier to find issues).

Regarding functions and lambda there's no difference...

Maybe Google for python performance tips but I think you're better off learning how to write good, readable Python first.

Thread Thread
 
vishwasmahadev profile image
Vishwas Mahadev

Thanks for your suggestion and I will check them for sure..