The video owner has disabled playback on external websites.
This video is no longer available on YouTube.
This video cannot be played right now.
Watch on YouTube
Unlock AI-Powered Learning Tools
Sign up to access powerful tools that help you learn faster from every video.
Learning Python Feels Easy. Until It Isn’t.
Subtitles (636 segments)
Python is by far the most popular
programming language in the world right
now. If you look at the tobi index, the
difference especially since past few
years is staggering. It's become the
main language of AI, machine learning,
data analysis, automation. It's getting
very popular for backends as well with
fast API due to its large ecosystem of
tools. And on top of that, it's really
simple to get started with Python. But
there's problem though. In my
experience, the learning curve for
Python looks something like this.
Learning the basics seems really easy
and you can build up your skill really
fast, but then you enter a sort of no
man's land where you're basically on
your own. Python has very few safety
nets. Use type annotations or not. Use
functions or classes or whatever you
want. You can override dunder methods to
your liking. And then there's advanced
stuff like generators and context
managers and protocols. Going from
beginner to expert in Python is actually
really hard, much harder than for
example Rust where you know once you
survive the borrow checker ownership and
lifetimes well writing a full-blown CLI
isn't that much harder than a hello
world program. Now, in this video, I'm
going to focus on how to become better
at Python after that initial honeymoon
and the exact steps I would take if I
wanted to become really good at Python
faster. Basically, the things I wish I
knew 10 years ago. This video is
sponsored by Data Camp. Talk more about
them later. The first step, the most
important one, is to master the core.
Most people try to rush through the
basics, but these are actually really
important. you need to make sure that
you don't have them wrong because if
that happens then basically everything
that you do afterwards is going to get
even worse. What is the basics? It's
things like conditionals, dictionaries,
loops, functions, things like that.
Things that Python is actually really
good at. So let's say as an exercise you
want to build a dictionary that maps
strings to their length but only
includes words that are longer than four
characters. So here I have a simple main
function that has a list of words and
then prints out those words. Very basic,
right? But already if you want to learn
the fundamentals, you need to know, hey,
I need a main function. And the reason
you want that, you don't want to just
put this at the top level in your Python
script is that you don't want to pollute
the global namespace because this words
variable is then going to be accessible
everywhere and you don't want that. So
that's why you need a main function.
This type annotation here doesn't return
results. it returns none. And then we
have this little bit here that makes
sure that if you run this script that
it's actually going to call this
function because that's not going to
happen automatically. So that's a basic
setup, fundamental setup of a Python
script. And then if we want to do this
exercise where we map these words to
their lengths, well then we're going to
need a dictionary.
Let's call that a length map. And this
is a dictionary of well strings to
integers. And initially we have it as an
empty dictionary. Also here you don't
strictly need to add this type
annotation but it actually clarifies the
code. We now know that the length map
map maps strings to integers. That's the
dictionary. Now next step you might want
to do in this case to solve this
exercise to make this mapping is to use
a for loop which of course Python also
has. So for each word in the list of
words, if the length of that word
is more than four,
then we're going to add it to the map.
And then finally, let's print this
length map. So this combines a bunch of
different Python fundamentals, right? We
have functions, we have a list, we have
a dictionary, we have a for loop, we
have a conditional statement here. And
when I run this
then you see we get Python and refactor
which are both words that have more than
four characters and the other words it
ignores. A different way to do this is
to rely on a built-in Python feature
called a comprehension. Now most people
when they talk about comprehensions they
only think about list comprehensions but
you can actually also do it for
dictionaries and for sets. Many people
don't know that, but it's a core
fundamental thing to be aware of. So
instead of this for loop, what you can
do is basically refactor this into a
dictionary comprehension,
which is basically just going to be a
single line of code. So that's going to
be a word to the length of the word. So
that's going to be the map for word in
words.
if the length of the word is more than
four
like so. And now I can remove this
entire for loop here. And then this is
what we have. Let's run this. We'll get
Full subtitles available in the video player
Practice with Exercises
Generate vocabulary, grammar, and comprehension exercises from this video
Comments (0)
Login to CommentSign up to unlock full features
Track progress, save vocabulary, and practice exercises
Interactive Mode
Quiz
Correct answer:
Related Videos
Is This The Biggest Mistake Science Ever Made?
Stop Mixing FastAPI with Business Logic: Fix It with Ports & Adapters
How Soviet Smugglers Fought Censorship With X-Rays
Two-Minute Case Study - Data & Gabbana: Stitch Fix's Predictive Algorithms
You Stop Glowing When You Die
Late Night with Seth Meyers
Quiz
Correct answer:
Quizzes appear as you watch the video
Memory Tip
From this video
Start learning languages for free