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.

Scene Explainer Phrase Hunter Flashcard Review Shadowing Practice Talk Back
Sign Up Free
English 25:51 Science & Tech

Learning Python Feels Easy. Until It Isn’t.

Late Night with Seth Meyers · 41,189 views · Added 1 month ago

Subtitles (636 segments)

00:00

Python is by far the most popular

00:02

programming language in the world right

00:04

now. If you look at the tobi index, the

00:07

difference especially since past few

00:09

years is staggering. It's become the

00:11

main language of AI, machine learning,

00:14

data analysis, automation. It's getting

00:16

very popular for backends as well with

00:18

fast API due to its large ecosystem of

00:21

tools. And on top of that, it's really

00:23

simple to get started with Python. But

00:26

there's problem though. In my

00:28

experience, the learning curve for

00:29

Python looks something like this.

00:32

Learning the basics seems really easy

00:34

and you can build up your skill really

00:35

fast, but then you enter a sort of no

00:38

man's land where you're basically on

00:40

your own. Python has very few safety

00:43

nets. Use type annotations or not. Use

00:46

functions or classes or whatever you

00:49

want. You can override dunder methods to

00:51

your liking. And then there's advanced

00:53

stuff like generators and context

00:56

managers and protocols. Going from

00:58

beginner to expert in Python is actually

01:01

really hard, much harder than for

01:03

example Rust where you know once you

01:05

survive the borrow checker ownership and

01:08

lifetimes well writing a full-blown CLI

01:10

isn't that much harder than a hello

01:12

world program. Now, in this video, I'm

01:15

going to focus on how to become better

01:16

at Python after that initial honeymoon

01:20

and the exact steps I would take if I

01:22

wanted to become really good at Python

01:24

faster. Basically, the things I wish I

01:26

knew 10 years ago. This video is

01:28

sponsored by Data Camp. Talk more about

01:30

them later. The first step, the most

01:32

important one, is to master the core.

01:34

Most people try to rush through the

01:36

basics, but these are actually really

01:39

important. you need to make sure that

01:41

you don't have them wrong because if

01:43

that happens then basically everything

01:44

that you do afterwards is going to get

01:47

even worse. What is the basics? It's

01:49

things like conditionals, dictionaries,

01:52

loops, functions, things like that.

01:55

Things that Python is actually really

01:57

good at. So let's say as an exercise you

02:00

want to build a dictionary that maps

02:02

strings to their length but only

02:04

includes words that are longer than four

02:06

characters. So here I have a simple main

02:08

function that has a list of words and

02:11

then prints out those words. Very basic,

02:13

right? But already if you want to learn

02:15

the fundamentals, you need to know, hey,

02:17

I need a main function. And the reason

02:20

you want that, you don't want to just

02:21

put this at the top level in your Python

02:23

script is that you don't want to pollute

02:24

the global namespace because this words

02:27

variable is then going to be accessible

02:29

everywhere and you don't want that. So

02:31

that's why you need a main function.

02:33

This type annotation here doesn't return

02:35

results. it returns none. And then we

02:37

have this little bit here that makes

02:38

sure that if you run this script that

02:41

it's actually going to call this

02:42

function because that's not going to

02:44

happen automatically. So that's a basic

02:46

setup, fundamental setup of a Python

02:48

script. And then if we want to do this

02:50

exercise where we map these words to

02:53

their lengths, well then we're going to

02:55

need a dictionary.

02:58

Let's call that a length map. And this

03:00

is a dictionary of well strings to

03:03

integers. And initially we have it as an

03:07

empty dictionary. Also here you don't

03:09

strictly need to add this type

03:11

annotation but it actually clarifies the

03:13

code. We now know that the length map

03:15

map maps strings to integers. That's the

03:18

dictionary. Now next step you might want

03:20

to do in this case to solve this

03:22

exercise to make this mapping is to use

03:23

a for loop which of course Python also

03:26

has. So for each word in the list of

03:30

words, if the length of that word

03:34

is more than four,

03:37

then we're going to add it to the map.

03:42

And then finally, let's print this

03:45

length map. So this combines a bunch of

03:48

different Python fundamentals, right? We

03:49

have functions, we have a list, we have

03:52

a dictionary, we have a for loop, we

03:54

have a conditional statement here. And

03:56

when I run this

04:00

then you see we get Python and refactor

04:03

which are both words that have more than

04:05

four characters and the other words it

04:08

ignores. A different way to do this is

04:10

to rely on a built-in Python feature

04:13

called a comprehension. Now most people

04:15

when they talk about comprehensions they

04:17

only think about list comprehensions but

04:19

you can actually also do it for

04:21

dictionaries and for sets. Many people

04:23

don't know that, but it's a core

04:25

fundamental thing to be aware of. So

04:27

instead of this for loop, what you can

04:30

do is basically refactor this into a

04:32

dictionary comprehension,

04:35

which is basically just going to be a

04:37

single line of code. So that's going to

04:39

be a word to the length of the word. So

04:43

that's going to be the map for word in

04:46

words.

04:48

if the length of the word is more than

04:52

four

04:54

like so. And now I can remove this

04:56

entire for loop here. And then this is

04:59

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

Vocabulary & Grammar Comprehension Quiz IELTS Exam Writing Practice
Sign up to practice

Comments (0)

Login to Comment
No comments yet. Be the first to share your thoughts!

Sign up to unlock full features

Track progress, save vocabulary, and practice exercises

Start learning languages for free