쉐도잉 연습: #62 Python Tutorial for Beginners | Generators - 영상으로 영어 말하기 배우기

레슨 만드는 중...
1
Welcome back aliens, my name is Davin Reddy and in this video we'll talk about generators.
2
Now in the earlier video we have talked about iterators.
3
So normally we use iterators to print or to fetch one value at a time.
4
So let's say if you have a list of values, let's say 100 values, And if you want one by one value, what makes sense is to use iterator.
5
But there are small issues with iterator right?
6
The first one you need to get the iterator where you have to define those two functions.
7
Next and iter.
8
We don't want to do that.
9
We want Python to do it for us.
10
And that's where Python says, okay, if you want iterators, we will give you generators.
11
Okay, but now you will think we have two different concepts.
12
Not exactly.
13
Generators will give you iterators.
14
Our job is done, right?
15
So generator give you iterator.
16
But how exactly to create a generator?
17
So let's do that.
18
So what I will do is I will just jump to Another file which is gen .py, you can create your own file there.
19
And here let me define a function.
20
That's right, we have to define a function, not a class this time.
21
So let's say our function define and we'll do the same thing, we'll return the top 10 values.
22
So we'll say top 10 and this will return the top 10 value and I will call this as well.
23
So I will let me just say I have values and this will be top 10.
24
So top 10 is.
25
a function which will give you the iterator.
26
But hold on, a function cannot give you the iterator, right?
27
A function has to be something special.
28
So we have to convert this function into a generator.
29
And the way to do that is, Normally in function we write return, right?
30
So if you say return 5, so this values will be having 5.
31
But if you instead of saying return 5, if you say
32
e -gildify your job is done because e -gildify your special keyword which will make your function as a generator.
33
but now you will think what's the difference even return will
34
give you the value even it will also give you the
35
value what i will do is i will just go back here let me just print the value
36
and if you run this code
37
so you can see we got a different thing instead of
38
getting a value 5 we got a object of generator
39
and that's the thing you know because generator gives you an iterator
40
so this function is not a normal function this is a generator because we are using yield yes if you will be different.
41
A will also return the value back it will return in the format of a iterator.
42
And everyone knows if you want to fetch something from an iterator, we have to use the next Let's run this code and you can see we got 5.
43
But now you will think, okay, that's fine.
44
Even return give the same output, right?
45
No, there's a difference.
46
In yield, since it's a generator which will give you iterator, you can write multiple yield statements.
47
So let's say yield 1.
48
Let's copy this.
49
Let's do it for four times and then they will be having different values here 2, 3 and 4.
50
Now you can see we got 4 yield which is 1, 2, 3, 4 and if you run this code, you will only get the first value because you are saying next only once.
51
So this is same as iterator where you are getting multiple values, right?
52
So you got your own iterator without using next and iterator function.
53
Let me just do that one more time.
54
I will say next.
55
Yes, you can also say next and in bracket you can say valves.
56
That's a choice you have.
57
Otherwise, this will work.
58
You can see we got one, two.
59
In fact, we can also use a loop.
60
So let's use a loop.
61
I will say for I in valves.
62
I'll let you print I here.
63
The moment you do that, you can see it will print all the values for you.
64
The remaining values which is three and four.
65
This is how you can create the rate up just by using that one particular keyword which is yield.
66
Okay, now there is another example we can take here.
67
Example, let's say I want to print top 10 perfect square.
68
You can do that.
69
So let's create one.
70
So what I will do is I will just remove this part.
71
Okay, because the logic will change.
72
Everything else will remain same.
73
Let me just not do this.
74
Let's use a for loop to print all the values.
75
But what should be logic?
76
So what I will do is I will say I will take a variable
77
which is i initially or maybe n will do n is equal to 1
78
and now since we want to print all the perfect square we have to use a loop.
79
I will not be using a for loop here because indirectly for uses iterator.
80
Let's use while so I will say while n less than equal to 10
81
because we want to fetch top 10
82
and every time you find a new value you have to just have to say yield.
83
You can say sq is equal to n into n that's how you find a square.
84
Once you got this square you can simply say yield and you can say sq.
85
Okay, so we are sending the value right.
86
So it is almost same as return but then return will terminate the function this will not.
87
That's something you have to remember.
88
Now, once you say sq you have to say n
89
because you have to also iterate your n right you have
90
to say n plus is equal to one i guess our job is done this should work let's try
91
so i will just run this application
92
and you can see we got top 10 perfect square we got 1 4 9 16 25
93
so that's how you can do it
94
because this yield will give you the next next value
95
because see when you say you're running a loop you're fetching one by one value
96
so when you fetch the first value this yield will return one when the loop says hey i value, it will give you nine.
97
So that's how you create a iterator using a generator.
98
But the question is why someone will use a generator?
99
Think about this.
100
Let's say you are fetching 1000 records from a database.
101
So when you say you're fetching 1000 records, maybe you want to print all, or maybe you want to process something from those records.
102
So when you say you want to fetch 1000 records, all these 1000 records will be loaded in your memory.
103
We don't want that.
104
Maybe you want to work with one value at a time.
105
So let's say 1000 records, we want to work with one value at a time.
106
In that case, you can use generator instead of using, instead of fetching the entire list, you can fetch one by one value.
107
So that's something you can do with generator.
108
That's maybe you can call as a real -life example.
109
So this is how we use generator with the help of yield keyword.
110
So I hope you enjoyed this video.
111
Let me know in the comment section and do subscribe for other videos.
112
Bye.
113
you

이 레슨의 어휘와 말하기 포인트

이 B1 수준 말하기 레슨은 영상 “Python Tutorial for Beginners”을(를) 바탕으로 합니다. 가장 자주 반복되는 단어는 다음과 같습니다: value, iterator, generator, function, return. 이 영상에는 섀도잉할 문장 113개와 단어 1240개가 있습니다. 말하는 구간의 길이는 6:02입니다. 화자는 분당 약 206단어로 빠르게 말하므로 연음과 약하게 발음되는 소리가 많습니다. 단어의 86%가 영어에서 가장 많이 쓰이는 3,000단어에 속합니다. 나머지는 연습 전에 미리 확인해 두세요.

이 영상의 핵심 어휘

영상에서 가장 어려운 단어 9개를 발음, 뜻과 함께 정리했습니다.

단어발음뜻
generator 명사/ˈdʒɛnəɹeɪtə(ɹ)/발전기
yield 동사/jiːld/생산하다
fetch 동사/fɛt͡ʃ/가지고 오다
loop 명사/luːp/고리
keyword 명사/ˈkiː.wɜːd/키워드, 핵심어
valve 명사/ˈvælv/밸브
bracket 명사/ˈbɹækɪt/괄호
subscribe 동사/səbˈskɹaɪb/구독하다
database 명사/ˈdeɪtəˌbeɪs/데이터베이스

영상에 나오는 구동사

단어뜻
go back 동사돌아가다

따라 말해 볼 만한 문장

영상에 나오는 짧고 완결된 문장으로, 일상 대화에서 그대로 쓸 수 있습니다:

  • We don't want to do that.
  • That's a choice you have.
  • I'll let you print I here.
  • That's something you have to remember.

이 영상의 문법

화자가 가장 많이 쓰는 문형을 영상 속 실제 표현과 함께 정리했습니다.

문형영상 속 표현
조건문 if + 절, will/would + 동사 — 조건과 그 결과if you want iterators, we will give · if you run this code, you will only
관계절 who / which + 절 — 사람이나 사물에 대한 추가 정보file which is · function which will · keyword which will
수동태 be + 과거분사 — 누가 하는지보다 무슨 일이 일어나는지에 초점is done · will be loaded
“should” 조언 should + 동사 — 하는 것이 좋은 일을 말할 때should be · should work

주의할 발음

화자는 we'll, you're, don't 같은 축약형과 약화된 형태를 10번 사용합니다. 들리는 대로 짧게 발음하세요.

  • 긴 단어 — 강세 위치에 주의: generator /ˈdʒɛnəɹeɪtə(ɹ)/, indirectly /ˌɪn.dɪˈɹɛk(t).li/

한국어 화자가 어려워하는 소리:

  • /f/ — ㅍ(/p/)으로 바꾸지 말고 윗니를 아랫입술에 대기: fetch /fɛt͡ʃ/, define /dɪˈfaɪn/
  • /v/ — ㅂ(/b/)과 구별하기: valve /ˈvælv/, convert /kənˈvɝt/, variable [ˈvæɹ.i.ə.bl̩]
  • /r/과 /l/ 구별하기: indirectly /ˌɪn.dɪˈɹɛk(t).li/, variable [ˈvæɹ.i.ə.bl̩]

이 영상으로 연습하는 방법

  1. 먼저 말하지 않고 영상을 끝까지 듣고 모르는 단어를 적어 둡니다.
  2. 0.75배속으로 한 문장씩 섀도잉을 시작하고, 익숙해지면 보통 속도로 돌아갑니다.
  3. 자신의 목소리를 녹음해 원본과 비교하고, generator, yield, fetch 같은 단어에 특히 주의합니다.

쉐도잉이란? 영어 실력을 빠르게 키우는 과학적 방법

쉐도잉(Shadowing)은 원래 전문 통역사 훈련을 위해 개발된 언어 학습 기법으로, 다언어 학자인 Dr. Alexander Arguelles에 의해 대중화된 방법입니다. 핵심 원리는 간단하지만 매우 강력합니다: 원어민의 영어를 들으면서 1~2초의 짧은 지연으로 즉시 소리 내어 따라 말하는 것——마치 '그림자(shadow)'처럼 화자를 따라가는 것입니다. 문법 공부나 수동적인 청취와 달리, 쉐도잉은 뇌와 입 근육이 동시에 실시간으로 영어를 처리하고 재현하도록 훈련합니다. 연구에 따르면 이 방법은 발음 정확도, 억양, 리듬, 연음, 청취력, 말하기 유창성을 크게 향상시킵니다. IELTS 스피킹 준비와 자연스러운 영어 소통을 원하는 분들에게 특히 효과적입니다.

섀도잉 방법: 단계별 전체 가이드 읽기 →