Тёмный

Python Coding Problem: Creating Your Own Iterators 

Corey Schafer
Подписаться 1,4 млн
Просмотров 67 тыс.
50% 1

Опубликовано:

 

7 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 225   
@coreyms
@coreyms 5 лет назад
There are usually multiple solutions to problems like these. If your solution is different than the ones I gave here then it is not necessarily wrong. For example, it would have been possible to use a try/except block in the next method as well. If you have different solutions that work then I would love to see them. Also, quick correction: At 3:05 I said "class attribute" when really I meant "instance attribute".
@lacocodelfitness1
@lacocodelfitness1 4 года назад
what is the best or fastest solution?
@andrewl.8626
@andrewl.8626 4 года назад
@@lacocodelfitness1 The simplest solution I could come up with was only 5 lines. class Sentence(): def __init__(self, sentence): self.words = sentence.split(" ") def __iter__(self): return self.words.__iter__()
@raiii-gamingandstuffs6965
@raiii-gamingandstuffs6965 4 года назад
def __next__(self): # EAFP try: current = self.current self.current += 1 return self.value[current] except IndexError: raise StopIteration
@stryderdominique4185
@stryderdominique4185 4 года назад
This Helped SO much you should totally continue these!
@eatbreathedatascience9593
@eatbreathedatascience9593 3 года назад
@@andrewl.8626 could help me understand what return self.words.__iter__() means ? I understand that next() return the item and move to the next time. What about iter() ? What exactly does it return that can move through the whole iterable ? Thanks very very much.....
@Skaxarrat
@Skaxarrat 5 лет назад
Coding challenges are even better than the tutorials
@koungmeng
@koungmeng 5 лет назад
i think so
@carlfranz6805
@carlfranz6805 5 лет назад
I find them easier to follow and undetstand.
@umaraftab6073
@umaraftab6073 5 лет назад
Corey, I am just amazed at how you deliver a complex concept so easily - I actually meant the word "deliver". You actually do that so good brother. Lucky to have an instructor like you on RU-vid. Thank you so much for your great stuff.
@geoptus
@geoptus 5 лет назад
HI Corey, these coding challenges are a great idea - great way to get us thinkin'. I hope you make these a regular feature : )
@lovechukwuegbo1589
@lovechukwuegbo1589 2 года назад
I wish i could add a thousand more 'likes'..
@apollossevere8602
@apollossevere8602 5 лет назад
Dude you MUST keep this up! We seriously need examples on how to use all of the functions and statements etc, we've learned into solving common problems. So thank you for this🙏.
@tradingguru8775
@tradingguru8775 5 лет назад
These videos are better than theoritical concepts. It gives us insight into real world problems. Keep up the good work.
@mohamedgomaa7793
@mohamedgomaa7793 4 года назад
Thanks so much for effort you are the best. This is my solution for generator def sentence(sentence): words = sentence.split() index = 0 while index < len(words): yield words[index] index += 1
@jipeejoce1353
@jipeejoce1353 5 лет назад
Please, continue to make this type of 'coding challenge' videos. They' re essentials in my opinion.
@RealToriMan
@RealToriMan 5 лет назад
I just want to save I love your calm voice and easy-to-understand explanation, no 'uhh' or 'err' in your explanation that can interrupt my focus while listening to your explanation
@deepdabbler
@deepdabbler 5 лет назад
Hi Corey, Please keep posting coding problems. These are great for practicing and solidifying one's understanding of the concepts you teach. Is there a reason you store both the original string and the list in the class object? Wouldn't the memory requirements be more? It seems to me that storing only a list would be sufficient (at least my solution works with just a list).
@prateekjha6862
@prateekjha6862 5 лет назад
A video tutorial series on 'Data structures and Algorithms' would be great. I know this might take up a lot of time, but almost every interview has questions from DSA. Your tutorial series on Django helped me a lot at my current project. Thanks.
@johnathaningle8812
@johnathaningle8812 5 лет назад
I totally agree Corey would be amazing at explaining DSA!
@andymao3946
@andymao3946 5 лет назад
Exercises like this one help me learn quicker. Your comment about using generator more frequently also provides a valuable reference as I learn Python. I'd like to see more coding exercises please.
@orbitblade8631
@orbitblade8631 5 месяцев назад
hey, I've written another class code that works: # Class code class Sentence: def __init__(self, sentence): self.sentence = str(sentence) self.words = self.sentence.split() def output(self): for words in self.words: print(words) mysentence = Sentence("This is a test") mysentence.output() # Generator code def Sentence(a): a = str(a) words = a.split() for word in words: print(word) Sentence("This is a test") """ Output: This is a test """ this seems way simpler than the one that you have explained in the video
@manavshah6811
@manavshah6811 3 года назад
Genuine Query: Wouldn't using sentence.split() defeat the whole purpose of using a generator in the first place? Per my understanding, generators are used because of two main reasons. First, they do not require additional storage. By using the split() method, I would argue that an array is being created that occupies O(n) space where n is the no. of words. Second, generators are better because they eagerly return/yield results when the actual computation is lengthy. By using split, we are already traversing the entire sentence. Please clarify how this implementation that uses generators, is helpful. Corey, if you are reading this, I can't thank you enough for your videos! They have helped me immensely and I often frequent them when I need to jog my memory on a particular topic. Thanks!
@ghanteyyy
@ghanteyyy 5 лет назад
Coding problem seems to be very interesting like all videos of yours. Please continue this series.
@manjusvijaykumar5444
@manjusvijaykumar5444 5 лет назад
Hi Corey.. These coding problems are great. learnt a lot. Please continue them.
@iriswang6760
@iriswang6760 4 года назад
def my_sentence_gen(str): words=str.split() index=0 while index
@riskzerobeatz
@riskzerobeatz 5 лет назад
Simply the best Python channel on youtube :D Thanks Corey!
@okirschner001
@okirschner001 Год назад
I found a solution that is much simpler and 50% faster: class Sentence: def __init__(self, sentence): self.sentence = sentence def __iter__(self): return (self.sentence.split()).__iter__() You make the best tutorials, thx for that. The first time you gave a "Realworld" example, I hit subscribe. Most other tutorials are stupid and all the same. I am a noob myself, and just started, but after your glorious previous video I came up with this solution by myself, glad I did not peak. An iterator already has an built-in __next__ function "Corey Schafer", so there is no need to overwrite the __next__ function. Also getting rid of 2 variables. But keep in mind my 50% more speed is only when you put the initialization included in the test..like: Anyway big thx for explaining iterators and iterables that in-deepth. from time import perf_counter start1 = perf_counter() for _ in range(100000): s1 = Sentence("This is a test") for word in s1: pass print(perf_counter()-start1)
@mylesmontclair
@mylesmontclair 5 лет назад
Hi Corey, I thoroughly enjoyed this coding problem. I found it to be challenging but not overwhelming and the content in the previous tutorial video was just helpful enough. You're the best teacher I've ever had in any subject. Thank you much!
@amolparnaik5132
@amolparnaik5132 Год назад
Didn't think you could change creating an instance so did def __iter__(self): while self.index
@janluka21
@janluka21 4 года назад
Hi Corey, using the split function will waste all the advantages of using a generator. I think the best way to do it, is just keeping in memory the current word and the index over the original sentence This is my solution: def gen_sentence(s): i, curr = -1, "" while i+1
@slavoie
@slavoie 5 лет назад
I definitely enjoyed this format! Splitting theory and practice into two videos makes it very easy and convenient to revisit the desired part. Even though I like finding a solution on my own to coding challenges, I really like to compare it to what an experienced programmer would do to find out where improvements could be made. Also, on more complex problems, it really helps to see if the structure of the program is correct and if something is missing (exception, test case, etc.). All in all, I love all your videos and this one makes no exception, except on StopIteration ;).
@serhiypidkuyko4206
@serhiypidkuyko4206 3 года назад
Thank you for your video-tutorials Carey. They are extremely useful (as well as awesome). As for this one I think that implementation has a ideological shortcoming. I mean using both in your class and in your generator the split() function. For example: the main reason to create and use generator - to be better in terms of both memory use and performance in larger programs. But your code produces all the list (of words) at once, the list your are going to loop over one-by-one. If I am wrong persuade me please.
@johnnybegood8669
@johnnybegood8669 5 лет назад
-zero dislikes -everyone liked that
@ForsakePariah
@ForsakePariah 5 лет назад
Corey, please, drop everything you're doing and come teach at my university. I have spent HOURS trying to understand this. Thank you!
@guyzee5251
@guyzee5251 5 лет назад
perfect timing with this one Corey; I just spent some time tinkering with the collections module! This made it 'click'
@LucidProgramming
@LucidProgramming 5 лет назад
Clear, clean, and concise. Your videos are an inspiration to my own channel on Python. I would really love to collaborate on a RU-vid tutorial project with you should you be receptive to that idea. Cheers, and thanks again for the video.
@coreyms
@coreyms 5 лет назад
Just looked at your channel and it looks like you have some great content! And I'd like to do some collaborations with some channels in the future, but I'm a bit too busy at the moment. I'll be sure to write you down as someone to contact if the opportunity opens up though. Keep up the good work and good luck with the channel.
@LucidProgramming
@LucidProgramming 5 лет назад
Wow Corey, thank you very much. Coming from you, that's a really sincere and excellent comment and definitely boosted my mood! I entirely understand that you're a bit too swamped at the moment to take on new projects, but even if there's something that I could help out with on your channel, like producing some content, I would be happy to discuss that further. In any case, thank you so much for your words of encouragement. Please do keep me in mind, it would be an honor to work with you!
@k_drive
@k_drive 3 года назад
thought i understood the tutorial completely till it came time to do this practice question 😂 cheers for the explanation at the end there
@techcode_man
@techcode_man 5 лет назад
Corey, this is an excellent idea. Please continue to provide such sample problems. Two Thumbs up!
@mohammedthahajk7619
@mohammedthahajk7619 5 лет назад
i did a seminar on python programming just by learning from your videos. Thanks a lot corey. I sincerely request you to make videos on GUI with python please
@DrDeuteron
@DrDeuteron Год назад
For everyone worried str.split using memory, here is a iterative splitter (which may be improved by the := operator, and possibly some operator.methodcaller on 'pop' to empty word into "".join and reset it to []): def isplit(sentence): sentence = collections.deque(sentence) word = [] while sentence: letter = sentence.popleft() if sentence == ' ': yield "".join(word) word = [] else: word.append(letter) yield "".join(word)
@arashchitgar7445
@arashchitgar7445 5 лет назад
Hi, Thanks for your great tuts. I've got 2 questions: 1- In the last video you said we use this iterator/iterable stuff in order to not keeping our data in a list to prevent the memory overload, but you are still keeping the sentence in a list. what's the part I got wrong? 2- When we use the next() method, we move the state to the next position, so how can we reset that and get back to the first position?
@StankyPickle1
@StankyPickle1 5 лет назад
Wish these videos were around when I was first learning. Keep up the good work!
@mohit4u007
@mohit4u007 4 года назад
Seperate problem video are much appreciated Corey.
@henrylin2008
@henrylin2008 5 лет назад
Thanks for excellent explanation and great example! would love to see more of coding problems!
@DishankTak
@DishankTak 3 года назад
split function uses memoery to story a list of words in an array and also take up some time. The main moto rather purpose of uisng iterator or generator is that 'retrieveing the data without using space at runtime'. But using spilt we are completely opposing the purpose. Correct me if i am wrong. I am a Learner too.
@3hurricane4mark7
@3hurricane4mark7 5 лет назад
Great! This will enhance your lessons, and adhere to a standard if and when you decidec to group them into training courses. Thanks again Corey.
@manojrpoojari8975
@manojrpoojari8975 5 лет назад
Your videos are always really good. And these coding problems would be a bonus. Thank you.
@thiagocavila
@thiagocavila 4 года назад
Excellent tutorial and challenge. I just found that your solution to the problem wasn't going to use split() as it would create a list of all words again in memory. Wouldn't this solution be space inefficient in terms of what you just explained in the tutorial?
@spaceyx
@spaceyx 5 лет назад
U are a very gifted person when it comes to teaching m8. Thank u so much!
@ketalciencia3163
@ketalciencia3163 5 лет назад
I Got a notifiaction for this video. I never subscribed or watched this channel. Ty RU-vid!!
@vitaliidmitriev7179
@vitaliidmitriev7179 5 лет назад
Thank you for the video! Here's what I came up with as a generator solution for word in (word for word in 'This is a test'.split()): print(word)
@wolfisraging
@wolfisraging 5 лет назад
Man your videos are so legid, keep it up. I have learned so much from you. Thanks
@StevenTse
@StevenTse 5 лет назад
practice makes perfect, coding problem is great. please keep on posting, thankyou
@saiabhilashbabu6382
@saiabhilashbabu6382 4 года назад
if I run below code , print statement executes only once. Looks like iterator not resetting. But we are able to for loop regular python lists multiple times. How it is possible?? for word in my_sentence: print(word) for word in my_sentence: print(word)
@sohailmmn9812
@sohailmmn9812 4 года назад
You definitely deserve much more followers. Well done.
@shaheerzaman620
@shaheerzaman620 5 лет назад
Hi Corey, My __next__ function is little different class Sentence: def __init__(self, input_string): self.input_string = input_string self.words = input_string.split() self.count = 0 def __iter__(self): return self def __next__(self): if self.count >= len(self.words): raise StopIteration value = self.words[self.count] self.count += 1 return value
@sahilnagotra547
@sahilnagotra547 4 года назад
this is a great idea, it would be great help if you upload this type of videos more often
@vishnurammageshvaran3484
@vishnurammageshvaran3484 5 лет назад
Good luck Corey I enjoy your video keep working hard and get success
@varunmallya5852
@varunmallya5852 4 года назад
Zero dislikes ladies and gentleman, Yes you read that right. Keep up the great work corey
@Jamlau
@Jamlau 5 лет назад
Really masterpiece,easy to understand.非常感谢您的教程,简单直白详实。
@kouroshjafari4238
@kouroshjafari4238 4 года назад
Thanks Corey for the great videos! I highly recommend coding problem videos.
@roderickdunn2517
@roderickdunn2517 2 года назад
Thanks Corey, great videos! Here's another solution with a generator expression. ge_sentence = (w for w in a_sentence.split()) [print(w) for w in ge_sentence]
@DrDeuteron
@DrDeuteron Год назад
map(print, sentence.split())
@umaraftab6073
@umaraftab6073 5 лет назад
I wish you do a video on encoding-decoding. I often times run into a problem with that. Thanks in anticipation.
@rahulparmar208
@rahulparmar208 5 лет назад
Very beneficial please continue with this
@mathiasborisvelicofftalave1205
@mathiasborisvelicofftalave1205 3 года назад
2k:4 like-dislike ratio, wish you uploaded more coding problem videos!
@Pd69bq
@Pd69bq 3 года назад
tbh id say explain under the hood principles behind some commonly used iterator "recipes" like zip(*[iter(string)] * n) is way more useful than just rewriting iter() function in several ways
@kyachahtahai
@kyachahtahai 3 года назад
Problem with treating Sentence as iterator (returning self from __iter__) is, state is not reset. We cannot run the for loop again over the same object of sentence. Ideally __iter__ should return a new iterator with fresh state. generator do takes care of that (we can also implement __iter__ of Sentence class as generator, if we still need class).
@ShubhamSharma-rm9ry
@ShubhamSharma-rm9ry 5 лет назад
coding challenges help learners that how to implement and help to remember the concept
@JohnDoe19840
@JohnDoe19840 5 лет назад
I love your videos. Your the best python teacher out there. Please can you do some more real-life examples with python
@DTW11
@DTW11 4 года назад
at 08:04, I have copied all the code but when I Run I get the error: 'Sentence' object in my_sentence is not iterable. How are you able to run yours without getting the same error? Thanks
@ahmedjumaah9727
@ahmedjumaah9727 5 лет назад
Hi Corey, thanks for the content. All your videos are very useful and your approach to explaining the topics is very clear. I have a suggestion, would it be feasible to do some video sessions on python for deep learning?, since it is a hot topic.
@ishpeace4886
@ishpeace4886 5 лет назад
well-explained! thanks Corey. Amazing way of teaching
@sharifmansuri607
@sharifmansuri607 4 года назад
Thanks for the coding problem video
@nabiladnan99
@nabiladnan99 3 года назад
my generator solution: def my_gen(sentence): words = sentence.split() i = 0 while i < len(words): yield words[i] i += 1
@patrickfreeman9094
@patrickfreeman9094 5 лет назад
Thumb up for the tutorial/problem combo.
@nabiladnan99
@nabiladnan99 3 года назад
This is some high quality teaching. You sir, are the best!
@madhu.badiginchala
@madhu.badiginchala 5 лет назад
Thank you Corey. Coding problems are very help to cement the concept. Also, could you please make tutorial on 'Python object memory optimisation' techniques. Thanks in advance.
@r125l6
@r125l6 2 года назад
Thank you so much for the coding exercise. Your tutorial is well designed and structured.
@mohamedkholti8755
@mohamedkholti8755 5 лет назад
Thank you a lot! this is very interesting. keep the coding problem idea !
@jingyuchang1885
@jingyuchang1885 5 лет назад
class Sentence: def __init__(self, sentence): self.sentence = sentence def __iter__(self): words = self.sentence.split() for word in words: yield word
@radaboy5755
@radaboy5755 2 года назад
# one liner sentence = "This is a test" word_generator = ( x for x in sentence.split( ) ) for word in word_generator: print(word)
@senolkurt7864
@senolkurt7864 4 года назад
Thank for the video! Absolutely, great idea to upload practice videos.
@adityaagarwal6611
@adityaagarwal6611 Месяц назад
I think the right solution will be this - class Sentence: def __init__(self,string): self.string = string def __iter__(self): self.current = 0 return self def __next__(self): temp = self.current while temp < len(self.string) and self.string[temp]!=" ": temp+=1 temp_current = self.current self.current = temp+1 if temp > len(self.string): raise StopIteration else: return self.string[temp_current:temp]
@sharifmansuri607
@sharifmansuri607 4 года назад
Thanks a lot for coding problem videos
@albertomedinarobredo
@albertomedinarobredo 5 лет назад
Hi Corey, Why do you include a instance variable self.sentence? It works fine directly doing self.words = sentence.split(), but I'm wondering if it would come up handy if you were to give other functionalities to the class. Thanks!!
@coreyms
@coreyms 5 лет назад
It's simply there to just have the original sentence available if it's needed for additional functionality as you said. We don't need to include it in this example.
@albertomedinarobredo
@albertomedinarobredo 5 лет назад
@@coreyms thank you for your quick response, and THANK YOU specially for your great tutorials. I started my programming and Python journey less than a year ago and I am grateful for your videos, which I find the clearest of all. I encourage you to continue with this coding problem series.
@roshansuthar7166
@roshansuthar7166 3 года назад
I would like to see more problems and solutions videos
@rohitjoshi4341
@rohitjoshi4341 2 года назад
I was just playing with the code you provided. I found that I could reset the self.index = 0 before raise StopIteration. This makes me resue my_sentence in multiple times loops. Otherwise, It will only work once.
@CyL3Nz
@CyL3Nz 5 лет назад
Corey, awesome tutorials! I wonder if you could create a series for gui frameworks with python? I'm not talking about tkinter which is well enough documented and fairly easy to understand but just way to narrow in its scope. I have tried learning wxpython or pyqt but I just can't wrap my mind around how these really work and the documentation especially for wxpython is horrendous.
@bakihussain4231
@bakihussain4231 5 лет назад
Yes please throw some problems for OOP series, Functions and other applications of python
@AbdurRahman-iy7nd
@AbdurRahman-iy7nd 3 года назад
def sentence(string): i_string = iter(string.split(' ')) while True: try: yield next(i_string) except StopIteration: break my_sentence = sentence('This is a test an I passed it') for word in my_sentence: print(word)
@402varun
@402varun 5 лет назад
why can't i be able to get the same output without the __iter__ method, as __next__ is anyways returning the value we want
@piotrs89
@piotrs89 5 лет назад
Hi, great video! However I have a question, what is a point of using iterator/generator if you create the whole list in your memory anyway? I thought that iterators are a way to get round this and not to hold everything in a memory. If we had a sentance with billion words, the program would crash when executing self.words = self.sentence.split(), wouldn't it?
@CyL3Nz
@CyL3Nz 5 лет назад
i had the exact same question, corey please answer
@taoge7521
@taoge7521 4 года назад
since self.index was already defined in the __init__ method, isn't it unnecessary to define it again in the __next__ method. overall, great video, much love. keep up the great content.
@jjhaak1240
@jjhaak1240 2 года назад
it is a local var, but not needed, just: return self.words[self.index - 1]
@gracedai6020
@gracedai6020 2 года назад
Hi Corey: Nice to have this practice in the subject - really helpful and interesting. Don't know if you can see this comment or not, but I have a question: for the generator, I tried to use the keyword 'return' rather than 'yield' and it returned the first element of the splitted list of words (sentence) 'letter_by_letter'; can you please explain the difference between 'return' and 'yield'?
@silverzero9524
@silverzero9524 5 лет назад
def sentence(sent): return iter(sent.split()) 3rd way (lazy)
@petersonfranklin1499
@petersonfranklin1499 4 года назад
... That is a brilliant idea ... It takes me almost one minute to understand why.
@VishalKumar-rg1yz
@VishalKumar-rg1yz 2 года назад
corey you are my guruvu ninnu epudu gurtupetukunta ayyaa
@wilsoncazarre
@wilsoncazarre 5 лет назад
My solution (I didn't saw the solution so far): class Sentence: def __init__(self, sentence: str): self.words = sentence.split(' ') def __iter__(self): self.index = 0 return self def __next__(self): if self.index >= len(self.words): raise StopIteration self.index += 1 return self.words[self.index-1] for word in Sentence('Testing this out'): print(word)
@meatyout
@meatyout 5 лет назад
Works fine with a for loop but have you tried saving your sentence in a variable and call next()? Doesn't work: "AttributeError: 'Sentence' object has no attribute 'index'". => self.index = 0 should be in __init__ not __iter__.
@hassnainamjad1059
@hassnainamjad1059 3 года назад
sir, in line 10 we are returning self ... i don't understand why .. anyone can explain plzzzz??
@PACKERSFANSheshank
@PACKERSFANSheshank 5 лет назад
I don't know if you will see this but if you do please please if you have the time make a video for hosting a flask application. I'm not able to understand any of the other tutorials and if you can make another video to the flask blog one showing how to deploy that on the internet free that would be great.
@usefmoorehead272
@usefmoorehead272 3 года назад
This was great!! I really enjoy your videos.
@rakesh989
@rakesh989 4 года назад
You're amazing. Thank you for all the videos.
@sungchulyonseiackr
@sungchulyonseiackr 4 года назад
def words_generator(sentence): # My initial pointer is pointing the start of sentence. idx = 0 # I use the while loop to generate words, # since I as a generator don't know how many words are out there. # # I don't want to use len(sentence.split()), # since len(sentence.split()) will produce a list and spend lots of memory. # This is againt the generator idea that saves lots of memory. while True: # I first check whether I stop generating. if idx >= len(sentence): break # If I decide to generate, here is the generating step: start = idx # start is the pointer of start of word end = idx # end is the pointer of end of word while True: try: # Usual Case Handling: if sentence[end] != ' ': end += 1 # move the end point to right if current character is not ' ' else: end += 1 # move the end point to right if current character is ' ' (final move) idx = end break except IndexError: # When I tried to identify the last word, # sentence[end] raises the IndexError. # So this is how I handle the last word case: end += 1 idx = end break yield sentence[start:end] #my_sentence = words_generator('This is a test') # www.nytimes.com/2020/09/21/technology/microsoft-zenimax-video-game-deal.html my_sentence = words_generator('Microsoft landed a major blow in its decades-long battle with its video game industry rival Sony on Monday, announcing the $7.5 billion acquisition of a video game company that narrowed the gap between the two tech giants’ offerings.') for word in my_sentence: print(word)
@readbhagwatgeeta3810
@readbhagwatgeeta3810 Год назад
Thank you so much for this wonderful solution 🙏🙏😍
@prabhathkota107
@prabhathkota107 5 лет назад
Beautifully explained
@darkfenix8283
@darkfenix8283 5 лет назад
Hey Corey , absolutely love your videos, could you recommend a channel for learning c++?
@user-fz8qy6tt3m
@user-fz8qy6tt3m Год назад
thanks for those vidoes! question about your class solution. isnt it LBYL coding style? class Sentense: def __init__(self, txt) -> None: self.words = txt.split() self.index = 0 def __iter__(self): return self def __next__(self): try: word = self.words[self.index] except IndexError as exc: raise StopIteration from exc else: self.index += 1 return word
@meatyout
@meatyout 5 лет назад
Is this a valid option (although a bit less readable...)? def sentence(sentence): gen = (word for word in sentence.split()) return gen Or without a function, a simple generator that we can loop over or print(next(gen)) gen = (word for word in sentence.split())
@sharp5641
@sharp5641 5 лет назад
This is Awesome!!! Waiting for more...
@parvizhagverdiyev5232
@parvizhagverdiyev5232 5 лет назад
thanks for your explanation,but i still cant get index side of code,please give me some resources..
Далее
Самое неинтересное видео
00:32
Просмотров 704 тыс.
Сказала дочке НЕТ!
00:24
Просмотров 846 тыс.
A Deep Dive Into Iterators and Itertools in Python
21:01
Modern Python logging
21:32
Просмотров 182 тыс.
10 Important Python Concepts In 20 Minutes
18:49
Просмотров 89 тыс.
15 Python Libraries You Should Know About
14:54
Просмотров 386 тыс.
Iterators vs. Generators in Python : Data Science Code
12:37
Python Generators Explained
28:37
Просмотров 154 тыс.
25 nooby Python habits you need to ditch
9:12
Просмотров 1,7 млн