1. 9
  1.  

  2. 3

    I realize that this is an exercise in performance golf at some level, but in my experience it’s usually not worth tweaking pure Python code for speed like this. In the end you’re still limited by the speed of the Python language and you’re probably left with code that is more obfuscated than a simpler but a little slower solution. Python is great for expressiveness and readability, not speed.

    There are better ways to get speedups anyway. Things like jit compilers (e.g. pypy and numba) and accelerators like Cython.