Hi Reader,
Tomorrow, I’m re-launching Python Essentials for Data Scientists to celebrate a HUGE course upgrade:
There will be a limited-time offer to celebrate the re-launch, so watch out for tomorrow’s email! 💸
I’ll be sending a few extra emails this week. I know your inbox is precious, so I’ll be giving you FREE access to 3 modules from the course! That way, you can benefit regardless of whether you choose to enroll. 💌
Thank YOU for being a valued reader! 🙏 Now let’s get to today’s tip…
Let’s say we had this list of words:
If we wanted to create a list of the word lengths, we could use a for loop:
We start with an empty list, and each time the loop runs, len(word) is appended to the list.
But as you might know, a list comprehension is even better for this scenario:
The effect is the same, but the code is much more concise.
Let’s now pretend that we wanted to create a dictionary containing both the word and its length. Once again, let’s use a for loop:
This time, we start with an empty dictionary, and each time the loop runs, a key-value pair is added to the dictionary.
You can actually convert this into a dictionary comprehension:
The structure is similar to a list comprehension, except there are curly braces { } instead of brackets [ ], and the first part of the comprehension (called the “expression”) is word:len(word) instead of just len(word).
You can read it as follows: “For each word, create a key-value pair of the word and its length.”
Visually, I really like the dictionary comprehension, since the “key:value” structure of the expression matches the way the dictionary prints out!
Let me know if you have any questions! đź’¬
Today’s tip is just one of the 22 NEW lessons from Python Essentials for Data Scientists!
If you want to build a solid foundation in Python and stay relevant in the world of AI, watch out for tomorrow’s email!
- Kevin
P.S. Weird Al Yankovic is human!​
Do you know someone who could benefit from learning Python? Please send them to pythoncourse.io so that they can hear about the launch! 🚀
Join 25,000+ intelligent readers and receive AI tips every Tuesday!
Hi Reader, This week, I've got a short tip about AI agents, followed by some Data School news... 👉 Tip #56: What are AI agents? Google is calling 2025 "the agentic era," DeepLearning.AI says "the agentic era is upon us," and NVIDIA's founder says "one of the most important things happening in the world of enterprise is agentic AI." Clearly AI agents are a big deal, but what exactly are they? Simply put, an AI agent is an application that uses a Large Language Model (LLM) to control its...
Hi Reader, Last week, I launched a brand new course: Build an AI chatbot with Python. 120+ people enrolled, and a few have already completed the course! 👏 Want to join us for $9? 👉 Tip #55: Should you still learn to code in 2025? You’ve probably heard that Large Language Models (LLMs) are excellent at writing code: They are competitive with the best human coders. They can create a full web application from a single prompt. LLM-powered tools like Cursor and Copilot can autocomplete or even...
Hi Reader, The Python 14-Day Challenge starts tomorrow! Hope to see you there 🤞 👉 Tuesday Tip: My top 5 sources for keeping up with AI I'll state the obvious: AI is moving incredibly FAST 💨 Here are the best sources I follow to keep up with the most important developments in Artificial Intelligence: The Neuron (daily newsletter) My top recommendation for a general audience. It’s fun, informative, and well-written. It includes links to the latest AI news and tools, but the real goldmine is...