What’s the shortest program for which we can’t tell if it stops?
Here’s a 10-line Python program. Nobody on Earth currently knows whether it ever stops. The halting problem is the question of whether, given a program, we can tell if it […]
Here’s a 10-line Python program. Nobody on Earth currently knows whether it ever stops. The halting problem is the question of whether, given a program, we can tell if it […]
In Python, Redis.hset function has ‘items’ that, per documentation “accepts a list of key/value pairs that will be added to hash “name“.”. You would think that it’s something like [(“key1”, […]
This is a follow up on this post. Default parameters are not the only way to do complex calculations in Python lambdas. Another idea is to use tuples and the […]
It’s pretty old stuff, but still… Here’s how you typically generate a random number in C++: Let’s dissect it a little. On the one hand, “random_device” is a rather nebulous […]
Summary Unlike many other languages, Python allows abstract static methods (see the reference). A class directly or indirectly deriving from abc.ABC cannot be instantiated, unless all its abstract methods are […]
TL;DR: Python statement from module import obj creates a copy of the object in the importing scope. In other words, from module import obj is roughly equivalent to obj = __import__(‘module’).obj. […]
Creation of Python packages underwent a few significant changes in the last 3-4 years. Here’s my note to self to remember what was changed/deprecated when: “Eggs” => “Wheel“ “Eggs” was […]
When serializing a dataclass, by default marshmallow-dataclass emits nulls for all fields that have the value of None. This is not necessariy most of the time and pollutes the resulting […]
TL;DR Python generator expressions can be iterated over only once. I mentally mapped Python generator expressions to C# IEnumerables, which can be iterated over multiple times. In reality, Python generator […]
TL;DR use marshmallow-dataclass. Serializing JSON into dataclasses with validation proved to be unexpectedly difficult. By “validation” here I mean type checking (this must be a valid integer), range checking (this […]