Do You Need to Escape a Dot in a Python Regex Character Class?

Question Recap the following regular expression concepts (more details in the article below): The dot character . in regular expressions matches any character excluding the newline character. For example, the pattern ‘c.t’ will match the strings ‘cat’, ‘cut’, or ‘czt’. The character class [ ] is a set of characters: if you use it in … Read more

Python __dir__() Magic Method

Python’s __dir__() magic method implements the functionality of the dir() built-in function. Semantically, dir() returns all (function, object, or variable) names in a given scope. However, the magic method __dir__() converts any return value to a sorted list. Minimal Example The following code defines a custom class My_Class and overrides the __dir__() magic method to … Read more

Ethereum Smart Contracts and EVM

In the previous posts, we developed simple smart contracts, deployed them using Remix or Truffle, and interacted with them using JSON-RPC interface providers such as using web3.py or web3.js. In this post, we shall take a closer examination into how a smart contract works on the Ethereum blockchain at the grass root. More precisely, we … Read more

­Pandas DataFrame abs(), all(), any(), clip(), corr()

The Pandas DataFrame has several methods concerning Computations and Descriptive Stats. When applied to a DataFrame, these methods evaluate the elements and return the results. Preparation Before any data manipulation can occur, two (2) new libraries will require installation. The Pandas library enables access to/from a DataFrame. The NumPy library supports multi-dimensional arrays and matrices … Read more

How to Print All Digits of a Large Number in Python?

In this tutorial, we will learn the different methods to print a large number in Python. And the contrast between printing integers or floats in those situations.   As you go through the article, feel free to watch my explainer video: Problem Formulation: Float vs Integer Printing Python by default prints an approximation in the case … Read more

The Shortest Quicksort Algorithm in Python

Quicksort is not only a popular question in many code interviews – asked by Google, Facebook, and Amazon – but also a practical sorting algorithm that is fast, concise, and readable. Because of its beauty, you won’t find many introductions to algorithms that don’t discuss the Quicksort algorithm. In this one-liner tutorial, you’ll learn about … Read more

Python __trunc__() Magic Method

Syntax and Definition object.__trunc__(self) The Python __trunc__() method implements the behavior of the math.trunc() function. For example, if you attempt to call math.trunc(x), Python will run the x.__trunc__() method to obtain the return value. We call this a “Dunder Method” for “Double Underscore Method” (also called “magic method”). To get a list of all dunder … Read more

[FIXED] fatal error: Python.h: No such file or directory

[toc] Problem Statement: How to fix “fatal error: Python.h: No such file or directory“? What is a “fatal” error? A fatal error causes a program to end with practically no warning without even saving its state. It usually occurs when an application attempts to access a piece of invalid information or data. The program closes … Read more

[FIXED] UnicodeDecodeError: ‘utf8’ codec can’t decode byte 0xa5 in position 0: invalid start byte

Introduction Problem Statement: How to fix “UnicodeDecodeError: ‘utf8’ codec can’t decode byte 0xa5 in position 0: invalid start byte” in Python? Using a specific standard to convert letters, symbols and numbers from one form to another is termed as Encoding. A Unicode character can be encoded using a variety of encoding schemes. The most common … Read more

Python __floor__() Magic Method

Syntax and Definition object.__floor__(self) The Python __floor__() method implements the behavior of the math.floor() function. For example, if you attempt to call math.floor(x), Python will run the x.__floor__() method to obtain the return value. We call this a “Dunder Method” for “Double Underscore Method” (also called “magic method”). To get a list of all dunder … Read more