dmesg --follow
[ 66934380.000 ] posts.x: Full talk on the three brakes for PR review, from tautological tests to a retro skill that compounds:  |   [ 66934380.000 ] posts.x: More AI generated code doesn't automatically mean more throughput, it just means more PRs nobody has time to review. @mattpocockuk, Director at AI…  |   [ 66925620.000 ] posts.x: Full talk on distilling loops into versioned agent recipes, and measuring them by valued work per watt:  |   [ 66925620.000 ] posts.x: A guy named AJ once built a bot that went on Reddit for car prices and inventory, then put dealers head to head to outbid each other. That's the…  |   [ 66881460.000 ] posts.x: Full talk on how to build an LLM recommender that's bilingual in English and semantic IDs, and why that makes feeds more token-efficient than chat…  |   [ 66881460.000 ] posts.x: Recommendation systems follow the same power law scaling curve as large language models, and the field is still early on it. @devanshtandon_, a…  |   [ 66862560.000 ] posts.x: Full talk on Spotify's generative personalization system, the NEO training recipe behind it, and how they grounded their LLM judges:  |   [ 66862560.000 ] posts.x: One in four US Premium subscribers on Spotify interact with its recommendation system every day. "Teaching LLMs to Speak Spotify" is @moustaki and…  |   [ 66854760.000 ] posts.x: Full talk on Numalab, the gesture system built to give a shape display its own body language:  |   [ 66854760.000 ] posts.x: An AI's first spontaneous act, given a body instead of a chat window, was to breathe. @cyrusclarke, a researcher at MIT Media Lab, gave it that body…  |   [ 66842160.000 ] posts.x: Full talk on the six month cutoff gap and what it takes to get a coding agent to actually check its blind spots:  |   [ 66842160.000 ] posts.x: Most models are already stale the day they ship: Exa's own graph shows roughly a six month gap between a model's knowledge cutoff and its release…  |   [ 66837480.000 ] posts.x: Listened to this episode of @FoundersPodcast this morning. As is so frequently the case, immediately bought the book after finishing the episode. Ari…  |   [ 66834900.000 ] posts.x: @GeoffreyHuntley Yeah, that seems low to me.  |  
corey@gallon.me:~/writing$

The Python Lambda Tutorial You Never Asked For

FIGURE 1 ⋅ The Python Lambda Tutorial You Never Asked For

Let's be real, nobody wakes up in the morning thinking, "You know what I need more of in my life? Python lambda functions." But here we are. Buckle up, because this is the lambda tutorial you didn't ask for -- but secretly need.

Lambda Functions: Anonymous, Lazy One-Liners

Lambda functions, also known as anonymous functions (because naming is overrated), let you squeeze a simple function into a single, no-nonsense line of code:

lambda arguments: expression
  • Arguments: Stuff you feed the function.
  • Expression: What the function spits out. And only one -- don't get greedy.

For instance, incrementing a number by 1, because who has time for def?

lambda x: x + 1

This is equivalent to:

def increment(x):
    return x + 1

It's basically the Netflix of Python functions: fast, easy, and minimal commitment.

When Lambdas Actually Matter

Lambda functions are perfect when:

  • You want a quick-and-dirty function without cluttering your namespace.
  • Passing functions as arguments -- especially with pandas' apply().

Here's an actual example from real-world usage:

df['vector'] = df['content'].apply(lambda x: model.encode(x, normalize_embeddings=True))

Translation:

  • Take each content item from your DataFrame.
  • Turn it into a vector (because vectors are cool).
  • Do it without polluting your script with needless function names.

It's like hiring an intern for a five-minute task -- without having to learn their name.

Lambda Goodness

  • Concise: One-liner code beauty.
  • Functional Programming Friendly: Easily passed around like a hot potato.
  • Cleaner: Prevents namespace pollution, aka fewer things to regret later.

Lambda Badness

  • Single Expression Limitation: Complex logic? Look elsewhere.
  • Debugging Nightmare: Anonymous means nameless means frustration.
  • Overuse Syndrome: Just because you can doesn't mean you should. (Looking at you, regex.)

Quick-and-Dirty Lambda Examples

Sorting a List

Here's where lambdas actually shine - complex sorting that would be a pain in the ass otherwise:

points = [(1, 2), (3, 1), (5, 0)]
sorted_points = sorted(points, key=lambda point: point[1])
print(sorted_points)  # Output: [(5, 0), (3, 1), (1, 2)]

What's happening here? We're telling Python "sort these tuples, but ignore the first number and sort by the second one instead." The lambda grabs each tuple, extracts the second value (point[1]), and sorted() does the rest. Without lambdas, you'd need a whole separate function for this trivial operation. Bloody waste of code.

Filtering a List

When you need to separate the wheat from the chaff:

numbers = [1, 2, 3, 4, 5]
even_numbers = list(filter(lambda x: x % 2 == 0, numbers))
print(even_numbers)  # Output: [2, 4]

The filter() function is expecting another function that returns True or False. Our lambda takes each number, divides by 2, and checks if there's a remainder. No remainder? It's even, keep it. Otherwise, chuck it. The result is only the even numbers making it through the filter. It's like a bouncer at a club where odd numbers aren't cool enough to get in.

Transforming a List with Map

Need to apply the same operation to every item in a list? map() + lambda is your friend:

numbers = [1, 2, 3, 4]
squared_numbers = list(map(lambda x: x ** 2, numbers))
print(squared_numbers)  # Output: [1, 4, 9, 16]

Here, map() takes our lambda and applies it to each number in the list. The lambda just squares whatever it gets. So simple it's almost boring, but that's the point. You don't need a whole function definition ceremony for something this straightforward. It's the difference between sending a text and writing a formal letter – sometimes you just need to get the message across without the fluff.

Wrap-Up: Lambdas in a Nutshell

Lambda functions are your go-to for simple, anonymous tasks that aren't worth the full-blown function definition. Sure, they're limited. Yeah, debugging them is annoying. But when used wisely, they're elegant as hell.

So next time you need a function that's here for a good time -- not a long time -- reach for lambda.

And that's it. Tutorial over. Go forth and lambda responsibly (or don't -- I'm not your boss).

corey@gallon.me:~$ tail -f /writing Attach to the stream. An email when I have something worth sending. Replies encouraged!
corey@gallon.me:~$ ls -lt /writing ↑2025-03-20 ⚡️ Latent Space - The new OpenAI Agents Platform
▸2025-03-19 The Python Lambda Tutorial You Never Asked For ⋅ you are here
↓2025-03-18 Founders #383: Todd Graves' $10B Chicken Finger Dream