Комментарии:
But how to get to the millionth of the lines by using yield?? Need to call the function for a million time??
ОтветитьI think i have found the best way to iterate a list using a function call without making complex counters outside the function hmmm
Ответитьpython yield keyword? question mark?
ОтветитьWeird question, why aren't you typing but it seems like you're copy-pasing the word by word or something?
ОтветитьWhat's the font he uses?
Ответитьamazingly explained
Ответить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?
ОтветитьThanks. Excellent video.
ОтветитьOmg in just 3 minutes you helped me out, new sub here <3
ОтветитьI failed a capital one interview today for not knowing this yield keyword.
ОтветитьHow do you type code without typing it? Magic?
ОтветитьFinally understood yield, thanks b001
Ответить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
What does open() do?
ОтветитьReally good explanation , i've been meaning to understand yield for a long time.
ОтветитьThis was better than most videos ive seen explaining this, and in a fraction of the time too
ОтветитьHi! What font & VSCode theme do you use?
ОтветитьThis is shaping up to be a good channel subscription. Thanks for the post
ОтветитьHey, awesome explanation and I loved the example! TY man 👍🏻
ОтветитьJust discovered your channel from TikTok and came here. You have no idea how useful this commentary based examples are. Great Job!
ОтветитьGreat video!
ОтветитьIsn't yield deprecated?
ОтветитьShort and sweet. You make fantastic videos.
ОтветитьInstead of yield keyword, you can use the in built readline() method in python for text files.
Ответить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
what theme do you have for vscode?
Ответить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?
Ответитьso its kinda like a linked list that is lazy loaded
Ответить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?
ОтветитьRemember to explicitly close the file after done reading it ))!
Ответить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)
Thanks
Ответить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.
ОтветитьWhat vscode theme is this?
Ответитьgreat way of explaining it! thanks!
ОтветитьGreat explination, bad example.
file.readlines() does the trick better.
Your theme looks a lot like Coffee at 2 AM
ОтветитьGreat tutorial although it would be even more helpful if you could include a for loop at the end to enhance the understanding.
Ответить🙌🙌
ОтветитьNoice video taught me a new concept. Thanks
ОтветитьIt would be really great if you could do short videos around Pandas. I love that your videos are short and to the point.
Ответить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?
Ответить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)
Interesting
ОтветитьIs there’s different between “”yield”” and “”readline()””
ОтветитьFinally! And it took only 3 minutes to get the idea, thanks! Awesome work!
ОтветитьLove your channel! Been binging all your vids on Python!
ОтветитьHmm. So, file by default iterates by lines, not by characters?
Ответить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 !
Ответить