Image by brgfx on Freepik
Python is one of the most popular programming languages among developers. It is used everywhere, whether it’s web development or machine learning.
There are many reasons for its popularity, such as its community support, its amazing libraries, its wide usage in Machine Learning and Big Data, and its easy syntax.
Despite having these many qualities, python has one drawback, which is it’s slow speed. Being an interpreted language, python is slower than other programming languages. Still, we can overcome this problem using some tips.
In this article, I will share some python tricks using which we can make our python code run faster than usual. Let’s get started!
Each data structure has a significant effect on runtime. There are many built-in data structures such as list, tuple, set, and dictionary in python. Most people use a list data structure in all cases.
In python, sets and dictionaries have O(1) lookup performance as they use hash tables for that. You can use sets and dictionaries instead of lists in the following cases:
- You do not have duplicate items in the collection.
- You need to search items repeatedly in the collection.
- The collection contains a large number of items.
You can see the time complexity of different data structures in python here:
Time Complexity via Python Wiki
This page documents the time-complexity (aka “Big O” or “Big Oh”) of various operations in current CPython…
Python’s built-in functions are one of the best ways to speed up your code. You must use built-in python functions whenever needed. These built-in fu