Premature Optimization is the Root of All Evil

This chapter draft is part of my upcoming book “The Art of Clean Code” (NoStarch 2022). You’ll learn about the concept of premature optimization and why it hurts your programming productivity. Premature optimization is one of the main problems of poorly written code. But what is it anyway? Definition Premature Optimization Definition: Premature optimization is … Read more

Как проверить вашу версию Python? Полезное руководство.

Для проверки версии Python, запустите python –version в командной строке (Windows), оболочке (Mac) или терминале (Linux / Ubuntu). Чтобы проверить версию Python в скрипте, запустите import sys, чтобы импортировать модуль, и используйте sys.version, чтобы получить подробную информацию о версии в коде. Давайте кратко рассмотрим различные способы проверки версии Python во всех операционных системах и средах. … Read more

Searching The Parse Tree Using BeautifulSoup

Introduction HTML (Hypertext Markup Language) consists of numerous tags and the data we need to extract lies inside those tags. Thus we need to find the right tags to extract what we need. Now, how do we find the right tags? We can do so with the help of BeautifulSoup’s search methods. Beautiful Soup has … Read more

Python any() Function

Python’s built-in any(x) function takes one iterable as an argument x such as a list, tuple, or dictionary. It returns True if at least one of the elements in the iterable evaluates to True using implicit Boolean conversion, otherwise it returns False. If the iterable is empty, e.g., any([]), it returns False because the condition … Read more

Python Regex Finditer()

You can create an iterable of all pattern matches in a text by using the re.finditer(pattern, text) method: Specification: re.finditer(pattern, text, flags=0) Definition: returns an iterator that goes over all non-overlapping matches of the pattern in the text. The flags argument allows you to customize some advanced properties of the regex engine such as whether … Read more

list.clear() vs New List — Why Clearing a List Rather Than Creating a New One?

Problem: You’ve just learned about the list.clear() method in Python. You wonder, what’s its purpose? Why not creating a new list and overwriting the variable instead of clearing an existing list? Example: Say, you have the following list. If you clear the list, it becomes empty: However, you could have accomplished the same thing by … Read more

Python all() Function

Python’s built-in all(x) function takes one iterable as an argument x such as a list, tuple, or dictionary. It returns True if all iterable elements evaluate to True using implicit Boolean conversion, otherwise it returns False. If the iterable is empty, all() returns True because the condition is satisfied for all elements. Argument x -> … Read more

Python abs() Function

Python’s built-in abs(x) function returns the absolute value of the argument x that can be an integer, float, or object implementing the __abs__() function. For a complex number, the function returns its magnitude. The absolute value of any numerical input argument -x or +x is the corresponding positive value +x. Argument x int, float, complex, … Read more

Python Regex – How to Count the Number of Matches?

To count a regex pattern multiple times in a given string, use the method len(re.findall(pattern, string)) that returns the number of matching substrings or len([*re.finditer(pattern, text)]) that unpacks all matching substrings into a list and returns the length of it as well. A few hours ago, I wrote a regular expression in Python that matched … Read more

Web Scraping With BeautifulSoup In Python

Summary: Web scraping is the process of extracting data from the internet. It is also known as web harvesting or web data extraction. Python allows us to perform web scraping using automated techniques. BeautifulSoup is a Python library used to parse data (structured data) from HTML and XML documents. The internet is an enormous wealth … Read more

Python Built-In Functions

Python comes with many built-in functions you can use without importing a library. The following table goes over all built-in functions in alphabetical order. If you click on any of the provided links, you’ll find an in-depth article with a short explainer video on the Finxter blog to help you improve your skills. Just follow … Read more

Python Regex Multiple Repeat Error

Just like me an hour ago, you’re probably sitting in front of your regular expression code, puzzled by a strange error message: Why is it raised? Where does it come from? And, most importantly, how can you get rid of it? This article gives you answers to all of those questions. Alternatively, you can also … Read more