Blog Posts
-
Using reduce() When You Need the Index
dr. Dobreff Csaba 10th jan 2026The reduce() function from the functools module in Python’s standard library is typically recommended for tasks that cannot be easily expressed using built-in language constructs such as comprehensions (list, set,...
-
Did You Know Context Managers Aren’t Just for File Operations?
dr. Dobreff Csaba 10th jan 2026When you first learn about context managers in Python — specifically the with…as… syntax — they’re usually introduced through file handling examples. That’s no surprise, since managing files safely is...
-
Be Careful: None Is Falsy, But Not Everything Falsy Is None
dr. Dobreff Csaba 10th jan 2026Let’s say we want to write a function that takes two arguments and runs a specific code block inside its body only if neither of the arguments is None. We...
-
OrderedDict Isn’t Dead Yet — Here’s Why
dr. Dobreff Csaba 10th jan 2026Do you still need [crayon-69e7349136e49460212328-i/] in your code now that dict preserves insertion order? Sometimes, we need dictionary items (key-value pairs) to retain the order in which they were added....
-
How to Define Truly Immutable Constants in Python
dr. Dobreff Csaba 10th jan 2026At first, this question might sound contradictory—after all, isn’t the whole point of a constant that its value doesn’t change? In theory, yes. But in practice, things are a bit...
-
How to Extract Elements from Deeply Nested Iterable Objects into a Single Container?
dr. Dobreff Csaba 10th jan 2026Let’s suppose we have a container object (such as a tuple) whose elements may include other containers, and those containers may themselves contain further containers. The goal is to create...
-
How to simplify the code and improve its readability with the partial() function?
dr. Dobreff Csaba 10th jan 2026The [crayon-69e73491371b3273427923-i/] function in the [crayon-69e73491371b6431457264-i/] module is used to create a new callable object from a callable object having multiple parameters by fixing the values of certain parameters, thus...
-
Why Are Annotations Useful?
dr. Dobreff Csaba 10th jan 2026In addition to comments written above or beside lines of code, as well as documentation strings (docstrings), Python also allows us to use annotations to help improve the understanding of...
-
How can you quickly and easily generate word frequency statistics from a text, stored as key-value pairs?
dr. Dobreff Csaba 10th jan 2026There are many ways to solve this problem, but short yet clear one- or two-line solutions are generally preferred. Below, we present two such approaches. What these two techniques have...
-
Did you know that a function in Python can have attributes?
dr. Dobreff Csaba 10th jan 2026You probably know that in Python, everything is an object. Objects have attributes that can represent data (e.g., numbers or strings), but they can also contain executable codes. These are...