Python Yield Keyword??

Python Yield Keyword??

b001

1 год назад

125,092 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@The_Gurugram_Voyager
@The_Gurugram_Voyager - 01.01.2024 20:51

But how to get to the millionth of the lines by using yield?? Need to call the function for a million time??

Ответить
@nojukuramu
@nojukuramu - 01.01.2024 19:44

I think i have found the best way to iterate a list using a function call without making complex counters outside the function hmmm

Ответить
@YuraSuper2048
@YuraSuper2048 - 25.12.2023 03:08

python yield keyword? question mark?

Ответить
@rami5801
@rami5801 - 16.12.2023 22:38

Weird question, why aren't you typing but it seems like you're copy-pasing the word by word or something?

Ответить
@kassu3603
@kassu3603 - 21.11.2023 06:03

What's the font he uses?

Ответить
@sayyampervaiz2646
@sayyampervaiz2646 - 19.11.2023 18:18

amazingly explained

Ответить
@jamesogletree5257
@jamesogletree5257 - 20.10.2023 02:46

I found you description of Python scopes very helpful, thanks. I also like the theme color you use. What the name of your theme color?

Ответить
@Among_us2014
@Among_us2014 - 14.10.2023 04:18

Thanks. Excellent video.

Ответить
@gabrielreyes8324
@gabrielreyes8324 - 20.09.2023 18:11

Omg in just 3 minutes you helped me out, new sub here <3

Ответить
@Geryf
@Geryf - 08.09.2023 05:07

I failed a capital one interview today for not knowing this yield keyword.

Ответить
@immortalsun
@immortalsun - 25.07.2023 03:56

How do you type code without typing it? Magic?

Ответить
@dariofairhall2695
@dariofairhall2695 - 22.07.2023 09:19

Finally understood yield, thanks b001

Ответить
@robsc7493
@robsc7493 - 21.07.2023 08:58

def getlines(file):
with open(file, ‘r’) as rfile:
for line in rfile:
yield line

Text = getlines(“myfile.txt”)

While True:
Line = (next(Text))
If Line == “what I’m looking for”:
Print(“found”, Line)
break

Ответить
@iaminfinityiq7182
@iaminfinityiq7182 - 24.06.2023 03:44

What does open() do?

Ответить
@garciajero
@garciajero - 23.06.2023 18:14

Really good explanation , i've been meaning to understand yield for a long time.

Ответить
@keifer7813
@keifer7813 - 29.05.2023 13:45

This was better than most videos ive seen explaining this, and in a fraction of the time too

Ответить
@Elon_Musk__6969
@Elon_Musk__6969 - 25.05.2023 18:07

Hi! What font & VSCode theme do you use?

Ответить
@FabianBarajas
@FabianBarajas - 16.05.2023 23:00

This is shaping up to be a good channel subscription. Thanks for the post

Ответить
@Aborrajardo
@Aborrajardo - 11.05.2023 03:46

Hey, awesome explanation and I loved the example! TY man 👍🏻

Ответить
@ZeeKay80
@ZeeKay80 - 09.04.2023 01:08

Just discovered your channel from TikTok and came here. You have no idea how useful this commentary based examples are. Great Job!

Ответить
@adrianl7318
@adrianl7318 - 24.03.2023 16:34

Great video!

Ответить
@user-kw3kc5hk8l
@user-kw3kc5hk8l - 24.03.2023 07:36

Isn't yield deprecated?

Ответить
@chaddrobertson5805
@chaddrobertson5805 - 24.03.2023 04:25

Short and sweet. You make fantastic videos.

Ответить
@sudharshanvijay2337
@sudharshanvijay2337 - 23.03.2023 22:35

Instead of yield keyword, you can use the in built readline() method in python for text files.

Ответить
@MechMK1
@MechMK1 - 23.03.2023 19:02

A much better example is a function tjat calculates the fibonacci sequence, as it is impossible to calculate everything at once.

Generators really shine in situations where returning an entire set is infeasible or even impossible

Ответить
@shaqtaku
@shaqtaku - 23.03.2023 11:07

what theme do you have for vscode?

Ответить
@abcdef-fo1tf
@abcdef-fo1tf - 23.03.2023 09:39

I don't get how this stops our program from saving the whole file. Since the generator needs to be able to output the whole file of text it's still storing it right?

Ответить
@roxasxiiidravenman8312
@roxasxiiidravenman8312 - 23.03.2023 07:48

so its kinda like a linked list that is lazy loaded

Ответить
@MsPocketMonsters
@MsPocketMonsters - 22.03.2023 17:07

What happens with file as you yield? Is it opened each time? Is the file read each until the last point each time? Or if it keeps open, when does it close? How can you reset the generator?

Ответить
@uiqman
@uiqman - 22.03.2023 13:23

Remember to explicitly close the file after done reading it ))!

Ответить
@cn-ml
@cn-ml - 22.03.2023 12:34

I think you missed a couple of essential properties of the yield statement and generator functions:
1. You can use a generator (yield keyword) to easily create custom iterables to use in for loops
2. You can also "yield from" other iterables, so you can omit the "for line in lines: yield line" in favor of "yield from lines"
3. You can send data from the caller to the yield statement using the generator send function (not important for beginner tutorial)

Ответить
@minsuksung
@minsuksung - 22.03.2023 09:41

Thanks

Ответить
@FreihEitner
@FreihEitner - 22.03.2023 04:05

That looks great except it appears you must know how many lines are in the original file in order to call 'next' on each one. I'm sure there is a way (I'll keep looking) to call 'next' exactly the number of times as the number of lines.

Ответить
@aramayiskhachatryan6528
@aramayiskhachatryan6528 - 22.03.2023 00:15

What vscode theme is this?

Ответить
@detached9
@detached9 - 21.03.2023 19:27

great way of explaining it! thanks!

Ответить
@Zawgg
@Zawgg - 20.03.2023 06:06

Great explination, bad example.
file.readlines() does the trick better.

Ответить
@AuracleTech
@AuracleTech - 20.03.2023 01:41

Your theme looks a lot like Coffee at 2 AM

Ответить
@SuadoCowboy
@SuadoCowboy - 19.03.2023 22:15

Great tutorial although it would be even more helpful if you could include a for loop at the end to enhance the understanding.

Ответить
@arhamsayyed9518
@arhamsayyed9518 - 19.03.2023 15:28

🙌🙌

Ответить
@StupidChess0
@StupidChess0 - 19.03.2023 14:44

Noice video taught me a new concept. Thanks

Ответить
@matthewosborn3093
@matthewosborn3093 - 19.03.2023 06:30

It would be really great if you could do short videos around Pandas. I love that your videos are short and to the point.

Ответить
@williamsquires3070
@williamsquires3070 - 19.03.2023 03:41

Okay, but won’t this hold the file open until all the lines have been read anyway? And what if the client code using the fetch_lines() function quits (or hangs) before reading all the lines?

Ответить
@TheGoldenPro
@TheGoldenPro - 19.03.2023 02:34

If you want to get all the lines you can actually iterate through the generator by using a for loop like so:

for line in zen:
print(line)

Ответить
@samueljehanno
@samueljehanno - 17.03.2023 21:55

Interesting

Ответить
@8xi_
@8xi_ - 17.03.2023 15:07

Is there’s different between “”yield”” and “”readline()””

Ответить
@SimpleExcelVBA
@SimpleExcelVBA - 16.03.2023 23:21

Finally! And it took only 3 minutes to get the idea, thanks! Awesome work!

Ответить
@turtlethom9127
@turtlethom9127 - 16.03.2023 23:14

Love your channel! Been binging all your vids on Python!

Ответить
@terciary
@terciary - 16.03.2023 22:54

Hmm. So, file by default iterates by lines, not by characters?

Ответить
@jean-claudefrancoisbaroudd730
@jean-claudefrancoisbaroudd730 - 16.03.2023 18:18

Just found your channel, I dabble in datascience in python, wrote some big projects in R and MatLab but not really anymore, this is AMAZING content ! Thank You !

Ответить