Rodrigo Girão Serrão 🐍🚀
@mathspp.com
1.1K followers 310 following 980 posts
I'll help you take your Python skills to the next level! Get a daily drop of Python knowledge 🐍💧 -> https://mathspp.com/drops Pydon'ts – free Python book 👉 https://mathspp.com/books/pydonts
Posts Media Videos Starter Packs
I'd just like to reiterate the honour it is to receive this award and I'm deeply humbled by the fact that all the other recipients (Katie, Sarah, and past recipients) have made such meaningful contributions to the community and yet I'm among them!

This is just the start :D
That's your 100th email right there:

“Hey folks, we're 100 emails and to celebrate I wanted to tell you what you can expect from the next 100 emails:

I have NO IDEA what's coming!

See you next week!”
There's just SO MUCH STUFF in Python 3.14. ✨

I decided I'm going to share the new updates, drop by drop, in my Python drops 🐍💧 newsletter.

If you want to learn about what's new in Python 3.14 without getting overwhelmed, subscribe 👉 mathspp.com/drops
Python drops 🐍💧 newsletter
Take your Python 🐍 skills to the next level. 🚀
mathspp.com
A recap? A bird's eye view of what happened? A sneak peek into what's coming?
Thanks for the link!

*Starts reading*

*Sees 172 collapsed items*

Oh boy, I didn't know I was about to read a novel 🤣
Maybe it's too early, but I'm having a hard time understanding the difference between `pathlib.Path.move` (new in Python 3.14) and `pathlib.Path.rename`.

Maybe the edge cases are different, but isn't the “main behaviour” the same?
I've turned this blog post cheatsheet into a downloadable cheatsheet.

You can get the cheatsheet from here: mathspp.com/blog/uv-chea...
High-contrast uv cheatsheet with common and useful commands to create and manage projects and its dependencies and lifecycle, working with scripts, managing Python installations, working with and installing tools, uv's interface for pip and venv, meta commands, and miscellaneous commands. You can find an HTML version and the link to download the high resolution images at https://mathspp.com/blog/uv-cheatsheet. Dark mode uv cheatsheet with common and useful commands to create and manage projects and its dependencies and lifecycle, working with scripts, managing Python installations, working with and installing tools, uv's interface for pip and venv, meta commands, and miscellaneous commands. You can find an HTML version and the link to download the high resolution images at https://mathspp.com/blog/uv-cheatsheet. Light mode uv cheatsheet with common and useful commands to create and manage projects and its dependencies and lifecycle, working with scripts, managing Python installations, working with and installing tools, uv's interface for pip and venv, meta commands, and miscellaneous commands. You can find an HTML version and the link to download the high resolution images at https://mathspp.com/blog/uv-cheatsheet.
I'm writing an email about how vegetarian lions relate to dataclasses.

If you subscribe quickly enough, you'll also get it.

(If you don't get it and you want to read it, reply to the welcome email and I'll forward it to you.)

Subscribe here 👉 mathspp.com/insider
Is this looking good?

(I'm turning my “uv cheatsheet” blog post into an actual cheatsheet you can download.)
uv cheatsheet with some useful commands to work with and manage tools. The cheatsheet shows two main sections, one with two commands for one-off tool execution based on uvx and a section with 5 commands to manage “permanent” tool installation based on "uv tool install" and other "uv tool" subcommands. All commands taken from https://mathspp.com/blog/uv-cheatsheet#managing-tools
Today I learned that around 4500 thousand years ago Egyptians already had 30 different types of bread.

I can't name 30 types of bread right now!
I only started using the word “yield” in my spoken and written English after learning about generators in Python! 🐍
Maybe better is to use str.isalpha?

sum(is_alpha for is_alpha, _ in groupby(my_string, str.isalpha))

(Of course all our solutions imply a slightly different definition of “word”.)

cc @ax3man1ac.online
Yesterday was the last day of the intermediate Python course cohort and we talked about packaging.

Folks were having so much fun using @crmarsh.com's uv to manage their toy projects and to package & publish them!

To share the joys of uv with even more people, I created a small uv cheatsheet:
Oh yeah exactly. I should've read this comment too before replying to the other 🤣
The previous methods also don't split on punctuation 🤷
For a more compact approach, see this comment using `itertools.groupby` in a brilliant way:

bsky.app/profile/ax3m...
No dunder methods, uses builtins and handles unicode...

sum(not is_space for is_space, _ in groupby(s, str.isspace))
Ahhh this is brilliant!

My take on your take:

```py
sum(not in_word for in_word, _ in groupby(s, whitespace.__contains__))
```

The opportunity to use `__contains__` directly was too good to pass up.
Here's a fun way of counting words in a string in Python.

This doesn't split the string then count, so it'll work for ridiculously large strings (e.g. files you can't load into memory)

Plus, I had fun making it branchless (i.e., without explicit `if`s) by doing arithmetic with the flag `in_word` 😅
A code snippet that shows a branchless word counter that works on a stream of data. Full code:

from string import whitespace

def wordcount(source_stream):
    count = 0
    in_word = False
    for codepoint in source_stream:
        count += (not in_word) and (codepoint not in whitespace)
        in_word = codepoint not in whitespace
    return count
    
print(wordcount("Hello, world!"))  # 2