Techno Blender
Digitally Yours.
Browsing Tag

Marcin

Python Inheritance: Should You Inherit From dict or UserDict? | by Marcin Kozak | May, 2023

In his fantastic book Fluent Python. 2nd ed., Luciano Ramalho explains why you should not create custom classes inheriting from dict. The reason behind this rule, strange at the first glance, is simple but critical: dict is a highly optimized type implemented in C, and it wouldn’t call the methods you overload in your subclass of dict.That would be a nasty surprise, wouldn’t it? Let’s see this in an example. Imagine you want to create a dictionary-like class in which the provided values will be converted to their string…

Python Dictcomp Pipelines in Examples | by Marcin Kozak | Apr, 2023

PYTHON PROGRAMMINGSee the power of dictcomp pipelinesPipelines process tasks one after another. Photo by Daniel Schludi on UnsplashThis article is motivated by a task I contributed to in a real life project a couple of years ago. After proposing the concept of comprehension pipelines, I noticed the solution could be nicely implemented using a dictcomp pipeline, with additional help of the OptionalBool data structure I proposed in yet another article.This article aims to show you how we can implement such a pipeline. I…

Comprehension Pipelines in Python | Marcin Kozak

PYTHON PROGRAMMINGComprehension pipelines are a Python-specific idea for building pipelinesComprehension pipelines take you straight to the goal. Photo by Anika Huizinga on UnsplashGenerator pipelines offer a Pythonic way to create software pipelines, that is, chains of operations in which each operation but the first one takes the output of the previous operation as its input:They enable you to apply transforming programming as described by Thomas and Hunt in their great book The Pragmatic Programmer:A typical generator…

Python Tuple: The Whole Truth | Marcin Kozak

PYTHON PROGRAMMINGLearn the basics of tuples and of using themTuples are often considered records. Photo by Samuel Regan-Asante on UnsplashThe tuple is an immutable collection type in Python. It’s one of the three most popular collection types in Python, along with the list and the dictionary. While I think that many beginning and intermediate developers know much about these two types, they may have problems with truly understanding what tuples are and how they work. Even advanced Python developers do not have to know…

Correlation Coefficient, and How to Misunderstand a Relationship | by Marcin Kozak | Jan, 2023

STATISTICSInterpreting correlation is far more difficult than most people think. Misinterpreting it, on the other hand, is not.Perfect correlation! Photo by Matt Seymour on UnsplashCorrelation… Who has not heard about correlation? We use this term so often and yet we don’t know too much about it. When you say, “These two things are correlated,” what do you actually mean? Or what do you mean when you say that the correlation between two things is strong?For data scientists and statisticians, correlation is even more…

Privacy of Attributes in Python OOP | Marcin Kozak

PYTHON PROGRAMMINGLearn what ‘public’ and ‘private’ means in the context of Python classes and their attributes.Photo by Dayne Topkin on UnsplashGenerally, in programming, when something is public, you can access it and use it; when it’s private, you cannot. It’s like thinking something versus saying something: When you think something, it remains yours; but whatever you say out loud stops being only yours and becomes public.Things work differently in Python. You probably heard that in Python nothing is really private.…

Python Documentation Testing, doctest, Marcin Kozak

PYTHON PROGRAMMINGdoctest allows for documentation, unit and integration testing, and test-driven developmentdoctest allows for keeping up-to-date code documentation. Photo by Ishaq Robin on UnsplashCode testing does not have to be difficult. What’s more, testing makes coding easier and faster — and even, at least for some developers, more pleasurable. For testing to be pleasurable, however, the testing framework we use needs to be user-friendly.Python offers several testing frameworks, currently three of the most popular…

Guide to Python comprehensions | Marcin Kozak

PYTHON PROGRAMMINGLearn the intricacies of list comprehensions (listcomps), set comprehensions (setcomps), dictionary comprehensions (dictcomps) — and even generator expressionsPhoto by Zuzana Ruttkay on UnsplashComprehensions constitute probably the most popular syntactic sugar in Python. They are so powerful that when I finally understood them, they blew my mind, and I love using them ever since.Yes, you got that right. The first time I understood comprehensions, not saw them. This is because, at first glance, they do…

Named Python Functions Using lambda | Marcin Kozak

PYTHON PROGRAMMINGDoing so is against PEP8, so why so many authors suggest this?In Python, the lambda keyword enables one to define anonymous functions. Photo by Saad Ahmad on UnsplashMany authors claim that in order to shorten your code, you can use lambda functions to define functions and assign them to a name. Some beginners may feel like trying this approach; to be honest, not only did I try it at some point, but also I enjoyed it too much.Note that this is a different situation from using an unnamed lambda function…

Use Linux, Even in Windows | by Marcin Kozak

Use the same operating system for development, testing and deploymentUse the same environment in DEV, TEST and PROD, so for development, testing and deployment. Photo by Tolga Ulkan on UnsplashThe six words below make today’s story:Deploying in Linux? Develop in Linux.This is more important than it may seem at first glance — for any software, and data-science products do not constitute an exception.Some may think the development environment is not that important, particularly when a programming language used in the…