Member-only story
5 Common Anti-Patterns in Python
Avoid using list comprehensions when input is large and more
“It’s not enough for code to work.” — Robert C. Martin
Python is one of the most popular languages in 2021.
The simple syntax makes it a popular choice for newbie programmers.
Because of the dynamic nature and flexibility, Python developers are sometimes prone to writing faulty, inefficient code.
This article will introduce readers to common anti-patterns found in Python and propose fixes that will lead to better developer practices.
1. Using map() and filter() On Iterable Objects
The inbuilt map
and filter
helps us transform iterable objects in Python via the principles of functional programming.
Both methods accept a function and an iterable as arguments and return a corresponding object.
This object can be transformed into a list by passing it as an argument into the inbuilt list
constructor in Python.
We often use lambda
functions as arguments to themap
, filter
functions: