map() vs. List Comprehension
Is the map() function faster than a corresponding list comprehension? That depends! Let's see how using lambda functions can affect the performance of map().
Is the map() function faster than a corresponding list comprehension? That depends! Let's see how using lambda functions can affect the performance of map().
Running one big blob of code is often faster than splitting your code into well-separated functions. But there are other ways you can improve the speed of your code without sacrificing its readability.
pathlib is an interesting, object-oriented take on the filesystem paths. With plenty of functions to create, delete, move, rename, read, write, find, or split files, pathlib is an excellent replacement for the os module. But is it faster?
With four different ways of formatting strings in Python 3.6 and above, it's time to look at which one is the fastest.
What's the best way to compare something to None in Python?
Is using dictionary comprehension faster than calling the dict() function? And what's the most efficient way to create a dictionary from two iterables?
Is using {} faster than dict()? If yes, then why? And when would you use one version over the other?
Can we speed up our code examples by simply upgrading the Python version? And if yes, by how much?
What's the fastest way to remove duplicates from a list?
What's the difference between type() and isinstance() methods, and which one is better for checking the type of an object?
Why iterating over the whole list is a bad idea, what data structure is best for membership testing, and when it makes sense to use it?
How can we compare a variable to True or False, what's the difference between "is" and "==" operators, and what are truthy values?
What's the fastest way to sort a list? When can you use sort() and when you need to use sorted() instead?
Simple "for loops" can be replaced with a list comprehension. But is it going to make our code faster? And what limitations list comprehension has?
Dictionaries in the latest Python versions preserve the insertion order. So, is there any reason to use the OrderedDict as we used to do in the past?
Numba library has plenty of tools to speed up your mathematical-heavy programs. From a simple @jit decorator, all the way to running your code on a CUDA GPU.
How to quickly find something in a collection of items, like a list or a range? When a generator expression is a great solution, and when it's not?
Is it faster to "ask for forgiveness" or "look before you leap" in Python? And when it's better to use one over the other?
Introduction to the "Writing Faster Python" series. What it is about, how do I benchmark, frequently asked questions, and additional resources.