Rodrigo Girão Serrão 🐍🚀
banner
mathspp.com
Rodrigo Girão Serrão 🐍🚀
@mathspp.com
I'll help you take your Python skills to the next level!

Advent of Code 🧑‍💻 live-stream https://www.youtube.com/@mathsppblog/live

Get a daily drop of Python knowledge 🐍💧 -> https://mathspp.com/drops
I'm going live to solve Advent of Code, day 2, in 10 minutes!

And we'll also be going back to the visualisation for yesterday's problem...

The link is in my profile :)
December 2, 2025 at 4:51 PM
Here's a lie developers tell themselves:

“Recursion is useless”

That's a coping mechanism because you're afraid of recursion...

But you shouldn't be afraid!
Recursion is actually nice ✨

And it's a very natural way to express certain algorithms...

Let me show you an example.
December 2, 2025 at 4:12 PM
This random tourist really took me by surprise:

So I arrived at the train station, saw a tourist couple trying to buy tickets, and offered to help.

They sorted the tickets out by themselves but wanted to double-check the platform they should be in.

I tell them the right one…
December 2, 2025 at 11:40 AM
Oh by the way, you can still get ALL my 8 Python books PLUS all future updates PLUS all future books for $37.5 because of the Black Friday craze.

That's $166 worth of books for a pretty penny.

Here's the link: 📚 mathspp.gumroad.com/l/all-books-...

Enjoy the books :)
“All books” bundle 🚀
This bundle gives you access to $153 worth of ebooks at more than 50% off:Pydon'ts ($29)The little book of itertools ($19)The little book of pandas & matplotlib ($19)The little book of pygame ($19...
mathspp.gumroad.com
December 1, 2025 at 8:04 PM
I may or may not have been muted for the first 2 minutes of the stream 🤣
My first Advent of Code live stream will start in ~1h!

See you there?

Advent of Code 🧑‍💻 live-stream: www.youtube.com/@mathsppblog...
December 1, 2025 at 7:28 PM
My first Advent of Code live stream will start in ~1h!

See you there?

Advent of Code 🧑‍💻 live-stream: www.youtube.com/@mathsppblog...
December 1, 2025 at 3:58 PM
With an article from yours truly 🤩
🐍📩 Pycoders Weekly (Issue 710) — FastAPI, Floodfill, 20 Years of Django, and More

buff.ly/16faoYR
November 27, 2025 at 10:37 PM
In today's session of the Algorithm Mastery Bootcamp we talked about linear recurrence relations and how to represent them as matrices.

The next step?

Using fast exponentiation with repeated squaring to compute terms at LIGHTNING FAST speeds ⚡️🤓
November 26, 2025 at 7:16 PM
This December I'll be publicly live-streaming myself solving Advent of Code (in Python) on YouTube, but I never streamed on YouTube.

Does anyone have any tips? :D

Both general streaming tips and specific YT-related ones?
November 25, 2025 at 2:42 PM
Reposted by Rodrigo Girão Serrão 🐍🚀
This post includes Python-related sales from @lernerpython.com, @mkennedy.codes, @stephengruppetta.com, @mathspp.com, and @dataschool.io.

...plus a bonus non-Python sale from @b0rk.jvns.ca because the zines are too good not to mention.
November 24, 2025 at 4:52 PM
One of my favourite things to do with Python 🐍 is trying to reimplement (parts of) modules.

I just have fun doing it. 🤷

And I was thinking about `itertools.pairwise` and its generalisation, `nwise`...

And how you could implement `nwise` in different ways.

Here's what I got:
November 24, 2025 at 8:15 PM
With the Black Friday deal (BF202550 for 50% off all my books), my book Python drops, with 179 Python tips, comes out at ~4 cents per tip...

That's a bit criminal 🤣

After the BF I'll have to increase the price of this book!

mathspp.gumroad.com/l/python-dr...
Python drops book and flashcards
mathspp.gumroad.com
November 24, 2025 at 2:25 PM
Inspired by @samwho.dev's brilliant interactive essays, I wrote an interactive explanation of the floodfill algorithm.

(Also in preparation for Advent of Code.)

Give it a read and let me know what you think -> mathspp.com/blog/floodfi...

I tried using PyScript for the interactive demos...
Floodfill algorithm in Python
Learn how to implement and use the floodfill algorithm in Python.
mathspp.com
November 23, 2025 at 1:45 PM
Ok, so I was writing a Python article about the floodfill algorithm.

It includes some interactive demos I created with PyScript!

I was still developing and testing the demos...

But someone shared it online in a major Python newsletter...

So, I guess the cat's out of the bag !
November 20, 2025 at 9:23 PM
Here's how to NOT get a file name from a path in Python.

The string method `split` has a counterpart `rsplit` that starts splitting from the end of the string.

This is useful if you only want the final segment(s) of a string.
November 20, 2025 at 3:57 PM
Who can guess what I'm writing about?
November 19, 2025 at 6:33 PM
Do you work in Hollywood or at a publisher?

If you do, I've got the perfect Python string method for you:

`str.title`

Changes the case of any string into title case.

“star wars: the empire strikes back”

becomes

“Star Wars: The Empire Strikes Back”.

Much more professional!
November 19, 2025 at 6:22 PM
Need a temp file in Python?

Maybe you need to test a function that requires a file-like object.

Or maybe you need a buffer because you're processing an amount of data so large that it doesn't fit into memory...

In these situations, `tempfile.TemporaryFile` can help you out.
November 17, 2025 at 4:28 PM
What I share in a Python tip:

You CAN use this data structure for this.
Note how, from a pedagogical standpoint, this is an instructive example.

What the commenters see:

You HAVE to use this code EXACTLY like this and this is the ABSOLUTE BEST solution in EVERY context.
November 17, 2025 at 11:34 AM
When doing Advent of Code I always end up needing a stack.

When I do, I create it by inheriting from `list`.

This gives me almost everything I want for free!
November 14, 2025 at 1:27 PM
33 likes on BlueSky? Am I famous now?!
You know what's a pain to implement in Python?

A moving average function.

Manually keeping track of all the values being considered for the window is a pain!

Unless you use `collections.deque`.

Its param `maxlen` makes the window automatically evict the values you don't need.
November 14, 2025 at 11:57 AM
I published an article about “everything related to functions”.

It was supposed to be a reference article...

And I forgot to talk about docstrings! 🤦

What's worse is that no one event pointed that out to me!

I've fixed it now: mathspp.com/blog/pydont...
Functions: a complete reference | Pydon't 🐍
This article serves as a complete reference for all the non-trivial things you should know about Python functions.
mathspp.com
November 14, 2025 at 11:19 AM
You know what's a pain to implement in Python?

A moving average function.

Manually keeping track of all the values being considered for the window is a pain!

Unless you use `collections.deque`.

Its param `maxlen` makes the window automatically evict the values you don't need.
November 13, 2025 at 6:19 PM
I was going through the OVERWHELMINGLY POSITIVE reviews of my book “Pydon'ts” and I always giggle when I find this 1-star review.

I mean, after 200 ⭐️⭐️⭐️⭐️⭐️ reviews, this anonymous user could think for a second and realise that the issue wasn't mine/the book's...

🤡
November 12, 2025 at 2:17 PM
This GitHub Action dorny/path-filters just saved me hours of work 🥵

I have a folder in a repo with cloudflare workers:

workers/
workerA/**
workerB/**

I want to deploy workers that get changed but not the others!

That's when dorny/path-filters comes in handy! ✨
November 12, 2025 at 1:59 PM