A Hidden Gem 💎 The Walrus Operator

Plus a newsletter restructure and more!

👋 Hey there!

I sat in a newsletter growth webinar last week and learned a thing or two. I’m implementing the suggestions made in that webinar in this newsletter.

Part of this change is a facelift, starting with the logo. Please let me know which logo you like best (P.S. More coming in 2024 😉)

Anyways, go vote by using the link above.

Here’s what’s in today’s newsletter:

  • The Python Pantry - A new section of curated links to help you become a better programmer.

  • Weekly snack? More like weekly snack attack! The coding challenge is now combined with the tip/trick.

  • And much more…

Forwarded this email? Sign up here for free.

🥐 The Python Pantry

Curated links to help you become a better programmer

Santiago explains how he’d start with machine learning from the beginning [link]

A guide on single and double underscores in Python names [link]

Django vs Flask - which is better? [link]

What features Python 3.12 has over 3.11, including better f-string parsing [link]

How business and companies ship to production [link]

💡 This Week’s Snack & Challenge

The weekly tip/trick and coding challenge

The walrus (:=) operator allows you to assign values to variables as part of an expression.

Using the walrus operator leads to more concise and efficient code.

It’s most useful in situations where you need to evaluate an expression then work with its result multiple times.

Here’s a simple example where you’re printing each line in a file using this operator:

Example of using the walrus operator

Walrus operators have 2 advantages:

  1. Reduces Lines of Code: It allows for shorter and potentially more readable code.

  2. Efficiency: It eliminates the need for a separate line of code to assign values, particularly within loops or conditionals.

Think you’re up for a challenge using the Walrus Operator? Try giving it a shot in this week’s challenge:

Write a Python function that reads lines from a text file until it encounters a line that says "END". For each line, the function should append the line's length to a list using the Walrus Operator for conciseness.


For example, given a file with the following contents:
Hello
Python
World
END

Your function should return [5, 6, 5]

📋️ How I Can Help

Looking to accelerate your Python skills? Here’s a way you can do so:

  1. Hire me as a Python coach. Get in touch today!

  2. Refer your friend to this newsletter and get a Python code optimization guide after 1 referral. See below for your unique link.

Did you enjoy this week's snack?

Login or Subscribe to participate in polls.

📧 Join the Python Snacks Newsletter! 🐍

Want even more Python-related content that’s useful? Here’s 3 reasons why you should subscribe the Python Snacks newsletter:

  1. Get Ahead in Python with bite-sized Python tips and tricks delivered straight to your inbox, like the one above.

  2. Exclusive Subscriber Perks: Receive a curated selection of up to 6 high-impact Python resources, tips, and exclusive insights with each email.

  3. Get Smarter with Python in under 5 minutes. Your next Python breakthrough could just an email away.

You can unsubscribe at any time.

Interested in starting a newsletter or a blog?

Do you have a wealth of knowledge and insights to share with the world? Starting your own newsletter or blog is an excellent way to establish yourself as an authority in your field, connect with a like-minded community, and open up new opportunities.

If TikTok, Twitter, Facebook, or other social media platforms were to get banned, you’d lose all your followers. This is why you should start a newsletter: you own your audience.

This article may contain affiliate links. Affiliate links come at no cost to you and support the costs of this blog. Should you purchase a product/service from an affiliate link, it will come at no additional cost to you.

Reply

or to participate.