シャドーイング練習: #62 Python Tutorial for Beginners | Generators - 動画で英語スピーキングを学ぶ

練習モードを選ぶ

各モードは全画面の練習ルームで開きます。

113 文
文が短すぎたり長すぎる場合は、Editをタップして調整してください。
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

アプリをダウンロード

流暢に話すために必要なすべて

AI発音採点文ごとに採点
IPA練習すべての音をマスター
単語学習自分の単語帳を作る
単語ゲーム遊びながら覚える

同じチャンネル

FOR YOU

おすすめ動画

このレッスンの語彙とスピーキングのポイント

このB1レベルのスピーキングレッスンは、動画「Python Tutorial for Beginners」を教材にしています。 繰り返し出てくる語は次のとおりです:value, iterator, generator, function, return。 この動画には、シャドーイング用の文が113文、単語が1240語あります。 音声の長さは6:02です。 話す速さは速く、1分あたり約206語です。音のつながりや弱く発音される音が多くなります。 単語の86%は英語の頻出3,000語に含まれます。残りは練習の前に確認しておきましょう。

この動画の重要語彙

動画の中で特に難しい単語11語を、発音と意味つきで紹介します。

単語発音意味
generator 名詞/ˈdʒɛnəɹeɪtə(ɹ)/発電機
yield 動詞/jiːld/もたらす
fetch 動詞/fɛt͡ʃ/持ち帰る
loop 名詞/luːp/ループ
keyword 名詞/ˈkiː.wɜːd/キーワード
valve 名詞/ˈvælv/バルブ
terminate 動詞/ˈtɝmɪneɪ̯t/止める, 打ち切る
bracket 名詞/ˈbɹækɪt/括弧
subscribe 動詞/səbˈskɹaɪb/購読する
variable 形容詞[ˈvæɹ.i.ə.bl̩]可変, 変えられる
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

注意したい発音

話し手はwe'll, you're, don'tなど、短縮形や弱形を10回使っています。聞こえたとおりの短い形で発音しましょう。

  • 長い単語(アクセントの位置に注意): generator /ˈdʒɛnəɹeɪtə(ɹ)/, indirectly /ˌɪn.dɪˈɹɛk(t).li/

日本語話者が苦手な音:

  • /r/ と /l/ の区別 — /l/ は舌先を歯茎につけ、/r/ はどこにもつけない: indirectly /ˌɪn.dɪˈɹɛk(t).li/, variable [ˈvæɹ.i.ə.bl̩]
  • /v/ — /b/ にならないように、上の歯を下唇に当てる: valve /ˈvælv/, convert /kənˈvɝt/, variable [ˈvæɹ.i.ə.bl̩]
  • /f/ — 「フ」ではなく、上の歯と下唇で出す: fetch /fɛt͡ʃ/, define /dɪˈfaɪn/

この動画での練習方法

  1. まず声を出さずに動画を最後まで聞き、知らない単語をメモします。
  2. まず0.75倍速で一文ずつシャドーイングし、慣れてきたら通常の速度に戻します。
  3. 自分の声を録音して元の音声と比べます。generator, yield, fetchなどの単語に特に注意しましょう。

シャドーイングとは?英語上達に効果的な理由

シャドーイング(Shadowing)は、もともとプロの通訳者養成プログラムで開発された言語学習法で、多言語習得者として知られるDr. Alexander Arguelles によって広く普及されました。方法はシンプルですが非常に効果的:ネイティブスピーカーの英語を聞きながら、1〜2秒の遅延で声に出してすぐに繰り返す——まるで「影(shadow)」のように話者を追いかけます。文法ドリルや受動的なリスニングと異なり、シャドーイングは脳と口の筋肉が同時にリアルタイムで英語を処理・再現することを強制します。研究により、発音精度、抑揚、リズム、連音、リスニング力、そして会話の流暢さが大幅に向上することが確認されています。IELTSスピーキング対策や自然な英語コミュニケーションを目指す方に特におすすめです。

シャドーイングのやり方: ステップ別の完全ガイドを読む →