Blog reconstruction in progress…

Sugar-free: Python dictionaries

The subject of our madness today is syntax sugar and Python dictionaries. Specifically, the operation of combining multiple dictionaries into one. We ask the following question as motivation:

Does there exist a function in Python that merges two or more dictionaries into a single, new dictionary?

There exist plenty of ways to merge dictionaries in Python, but are any of them functions with signatures like this?

def merge_dicts(dicts: Iterable[dict]) -> dict:
    # insert definition here

Why do I care about this?

Here’s the way it usually goes.

Read More →

Just enough Conda advice

Virtual environments seem to be a constant pain for researchers. Academics in particular seem to not really understand them, which causes a lot of startup pain when they want try out the Python language. The academics I used to roll with are heavy users of R, which has some environment management solutions (renv in particular), but they are not heavily used. Even in the industry world I see Python users complaining about environment pains. Stuff like, “broke my conda environment again…”.

Read More →

It’s perfectly fine to talk about the “median voter” like this

I am letting myself get nerd-sniped by some BlueSky politics discourse, and in my shame I will try to be quick with it.

In the aftermath of the 2024 election, “the left” has appeared divided about whether it should engage in more moderate politics to attract “the median voter”. Political scientist / respected mutual follow Jon Green shared his blog post about the assumptions behind the “median voter theorem” as popularized by Anthony Downs. The subtext of the post is, as I read it, “Let’s try to be a little more clear about what we’re talking about here.” He proceeds to describe the many brittle assumptions that motivate what we call “the Downsian model.” The model is a mathematical formalism, so the assumptions have a particular rigity to them:

Read More →

Bayesian modeling and three “pillars” of causal inference

Some background

My Ph.D. thesis contained some attempts to “do causal inference” with Bayesian modeling. It was interesting stuff, but the experience was disorienting. At the time, my field (political science) had very few cases where somebody did causal estimation with a Bayesian model. It had even fewer examples of anybody discussing “what it meant” to combine these things, if it meant anything at all.

I had neither the brains nor the self-sacrificial dedication to launch an academic career with this work. But I was writing a dissertation, and you try to push on a few things in a dissertation. Causal inference and Bayesian modeling are both big things that occupy a lot of brain space as you try to grok them. So I was kicking some ideas around.

Read More →

Scraping the ‘S.C.U.M. score’ data from the ‘Kill James Bond’ website

This post describes the process for scraping “S.C.U.M.” score data from the Kill James Bond podcast website.

To perform the scraping, we design a functional interface that lets us easily generate sequences of data and map functions over those sequences.

Along the way, we employ a functional optimization concept called memoization. Memoization, crudely, is when when a function “caches its own return value” to make repeated calls more efficient. Think of it like a function that remembers every argument it ever saw and every value it ever computed. If that sounds fuzzy, we explain it with more detail below.

Read More →