The fastest way to find the length of natural numbers in Python

My latest (and first!) post Why ‘d = {}’ is faster than ‘d = dict()’ sparkled a small debate in our group. In the article I found len(str(n)) to be ~37.64% faster than math.floor(math.log10(n) + 1). We all knew that len and str are super fast for what the… Read more

Similar

Learn Python 3 the Hard Way

Welcome to the 4th Edition of Learn Python the Hard Way which teaches Python 3. You can visit the companion site to the book at http://learnpythonthehardway.org/ where you can purchase digital downloads and paper versions of the book. The free HTML versi... (more…)

Read more »