Rodrigo Girão Serrão 🐍🚀
@mathspp.com
1.1K followers 310 following 970 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
mathspp.com
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.
mathspp.com
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
mathspp.com
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
mathspp.com
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!
mathspp.com
I only started using the word “yield” in my spoken and written English after learning about generators in Python! 🐍
mathspp.com
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
mathspp.com
I'm glad I could help :D
mathspp.com
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:
mathspp.com
Oh yeah exactly. I should've read this comment too before replying to the other 🤣
mathspp.com
The previous methods also don't split on punctuation 🤷
mathspp.com
For a more compact approach, see this comment using `itertools.groupby` in a brilliant way:

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

sum(not is_space for is_space, _ in groupby(s, str.isspace))
mathspp.com
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.
mathspp.com
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
mathspp.com
This brings back memories...
mathspp.com
Do you want to create professional-looking projects?

You'll need lots of shiny badges like the one you can see below for my most recent project 👇

You can create custom badges at shields.io, it's a pretty cool service!

Very professional, much wow!
A screenshot of a readme.md page with a badge that says “usefulness: very useful”.
mathspp.com
Everything you need to know about `functools.partial`:

👉 what it's for
👉 how to use it
👉 code examples

And even how to use it with `functools.Placeholder`, a new 3.14 feature.

youtu.be/LE66sVEMbi8
Understand functools.partial and Placeholder (new in Python 3.14) in 18 minutes
YouTube video by Rodrigo 🐍🚀
youtu.be
mathspp.com
I am happy to report that I didn't blunder anything today.
mathspp.com
Just got out from the 1st live session of this week's intermediate Python course.

The only thing I messed up was that I only remembered that I should be recording when I was ~10 min into the content 🤦

Otherwise it's going well :D
mathspp.com
OK FINALLY I RECORDED IT

But now I have day 2 of the cohort, so I'll publish later!
mathspp.com
Today I did a couple of false starts but today I'm publishing a video about `functools.partial` and the new Python 3.14 update.

What's something you don't understand about `functools.partial` that you wish I explained?
mathspp.com
It always gets me when I write :D in a GitHub issue and the emoji dropdown suggests a dagger 🤣
Screenshot of a GitHub text field to write an issue/discussion message and the user only added the text ":D", for a smiley face. GitHub suggests replacing the smiley face with the emoji of a dagger.
mathspp.com
Today we'll be talking about modular and composable code.
Then the std library.
Then typing.
Then managing projects & packaging.

That's the overall plan.

More info 👉 mathspp.com/courses/inte...