1 00:00:00,000 --> 00:00:03,200 Let's explore this idea of a generator. 2 00:00:03,260 --> 00:00:07,110 Now, generators are functions that allow you to write basically 3 00:00:07,120 --> 00:00:10,620 a function that can return some sort of data now and then 4 00:00:10,630 --> 00:00:12,690 later resume where it left off. 5 00:00:12,700 --> 00:00:16,050 Now, if this is your first time experiencing a generator, 6 00:00:16,059 --> 00:00:18,480 what I just said was probably extremely confusing. 7 00:00:18,600 --> 00:00:22,400 So let's think of a generator as something that's a lot more 8 00:00:22,400 --> 00:00:23,600 like a loop, 9 00:00:23,660 --> 00:00:26,060 but instead of being able to loop through something over 10 00:00:26,070 --> 00:00:28,460 and over and over again, we can only really loop through 11 00:00:28,460 --> 00:00:30,400 it once, and then it's totally exhausted. 12 00:00:30,440 --> 00:00:34,340 Now, the nice thing behind a generator is unlike a list where 13 00:00:34,340 --> 00:00:37,700 you have, let's say, [1, 2, 3, 4, 5], 14 00:00:37,700 --> 00:00:41,300 you know, maybe all the way up to a 100000. 15 00:00:41,360 --> 00:00:43,730 100001, something like that. 16 00:00:43,740 --> 00:00:50,280 A list is going to hold all of this in memory, so these are 17 00:00:50,290 --> 00:00:51,870 just small numbers, so that's okay. 18 00:00:51,990 --> 00:00:56,310 But what if these were entire classes, entire objects, huge 19 00:00:56,310 --> 00:00:58,800 dictionaries, it's going to hold all of this in memory. 20 00:00:58,860 --> 00:01:03,090 A generator does not do that. So that's what a list will 21 00:01:03,090 --> 00:01:07,400 do, but a generator won't store all the data all at once. 22 00:01:07,760 --> 00:01:11,720 So for instance, what a generator will do, is it will say, 23 00:01:11,720 --> 00:01:14,300 "Oh, okay, the first iteration is a 1. 24 00:01:14,300 --> 00:01:16,200 I don't know what the next item is". 25 00:01:16,200 --> 00:01:17,600 It has no idea. Not yet 26 00:01:17,670 --> 00:01:20,780 anyways. Until it gets to that second iteration, 27 00:01:20,790 --> 00:01:23,240 and then it applies a formula and says, "Okay, well, based 28 00:01:23,250 --> 00:01:26,910 on the last number, the math that went on behind 29 00:01:26,920 --> 00:01:30,470 to get that, I now know that the next number is going to 30 00:01:30,480 --> 00:01:34,440 be 2", and it has no idea what's coming after that. 31 00:01:34,450 --> 00:01:40,280 And then it applies the same formula that it got for the number 32 00:01:40,290 --> 00:01:43,820 2, and then it says, "Okay, well, I know that number 3 33 00:01:43,900 --> 00:01:46,800 is going to be number 3", and so on and so on and so on. 34 00:01:46,850 --> 00:01:50,390 Whereas a list knows all of those values already. 35 00:01:50,390 --> 00:01:54,460 Python knows every single value in this list from 1 to 36 00:01:54,520 --> 00:01:55,630 a 100000, to more, 37 00:01:56,000 --> 00:01:57,400 but a generator doesn't. 38 00:01:57,400 --> 00:02:00,190 A generator literally just looks for what it needs right 39 00:02:00,340 --> 00:02:03,160 now. So if you are in iteration four, it doesn't care about 40 00:02:03,170 --> 00:02:06,400 all the previous iteration, doesn't care about all the future 41 00:02:06,400 --> 00:02:10,199 iterations, all it cares about is the one that you're currently working on. 42 00:02:10,220 --> 00:02:14,330 Now, assuming that every number were to take up exactly one 43 00:02:14,330 --> 00:02:17,600 byte of data, if we had a million numbers in a list, we'd 44 00:02:17,600 --> 00:02:18,800 have a million bytes of data, 45 00:02:18,890 --> 00:02:24,680 and this list would be huge, in memory anyways, because one 46 00:02:24,680 --> 00:02:27,600 byte for number 1, 1 byte for number 2, 1 bite for number 3, 47 00:02:28,600 --> 00:02:31,400 and then you have to add all of those together. 48 00:02:31,400 --> 00:02:33,600 Whereas the generator, no, it doesn't do that. 49 00:02:33,670 --> 00:02:35,820 Generator just says, "Okay, you're on number 1, 50 00:02:35,830 --> 00:02:36,840 I'll just focus on that. 51 00:02:36,850 --> 00:02:37,980 You're on iteration 5, 52 00:02:37,980 --> 00:02:39,300 I'll just focus on that one". 53 00:02:39,300 --> 00:02:41,430 It doesn't store everything else in memory. 54 00:02:41,430 --> 00:02:43,400 So these are really, really performant. 55 00:02:43,700 --> 00:02:46,700 That said, once you loop through a generator, 56 00:02:46,720 --> 00:02:48,310 that loop is exhausted, 57 00:02:48,310 --> 00:02:49,700 you can't get that back. 58 00:02:49,700 --> 00:02:54,600 So you can really think of a generator as something that's 59 00:02:54,600 --> 00:02:57,500 just memorizing instructions, but it doesn't actually know 60 00:02:57,500 --> 00:02:58,800 all the answers, not right away 61 00:02:58,880 --> 00:03:02,480 anyways. Whereas a list might have all the answers already, 62 00:03:02,490 --> 00:03:04,220 a generator doesn't work like that. 63 00:03:04,220 --> 00:03:09,350 It's a lot like if I told you to add two really large numbers 64 00:03:09,360 --> 00:03:14,690 together. So if I told you to add this number and this number, 65 00:03:14,700 --> 00:03:17,690 well, at first glance, you probably could not do that in 66 00:03:17,700 --> 00:03:20,330 your head, not just by looking at this, but you could figure 67 00:03:20,330 --> 00:03:23,100 out how to add these two numbers together fairly easily. 68 00:03:23,180 --> 00:03:25,160 A generator does that exact same thing. 69 00:03:25,170 --> 00:03:28,430 A generator says, "I'm not going to worry about trying to 70 00:03:28,430 --> 00:03:31,300 figure this out right now until I actually need to". 71 00:03:31,360 --> 00:03:34,600 And then it says, "I don't even need to know the answer. 72 00:03:34,610 --> 00:03:38,820 I just know that by adding one of these", it just knows that 73 00:03:38,820 --> 00:03:42,400 by simply having a formula for adding numbers together, it 74 00:03:42,410 --> 00:03:43,970 can come up with the solution. 75 00:03:43,980 --> 00:03:45,980 So it already has the formula saved, 76 00:03:45,980 --> 00:03:49,500 it knows what to do, and it doesn't save the answer because 77 00:03:49,500 --> 00:03:51,650 it doesn't need to use that kind of processing power, 78 00:03:51,650 --> 00:03:52,800 not yet anyways. 79 00:03:52,800 --> 00:03:56,850 So now when we're looking at syntax, a generator is going to 80 00:03:56,860 --> 00:03:58,620 look a lot like a function. 81 00:03:58,630 --> 00:04:03,820 So we've got 'def my_generator', and it's going to use this 82 00:04:03,850 --> 00:04:08,800 word, this keyword 'yield', and it's going to yield some sort 83 00:04:08,810 --> 00:04:13,030 of result. Whereas in a function it's usually 'return', and 84 00:04:13,040 --> 00:04:16,370 then something. In a generator, you just 'yield' the result. 85 00:04:16,380 --> 00:04:19,670 And by simply using this 'yield' keyword, Python knows that 86 00:04:19,680 --> 00:04:21,980 this is now a generator, and it's not supposed to be a typical 87 00:04:21,980 --> 00:04:25,399 function. Now, we've actually worked with a generator in the past. 88 00:04:25,399 --> 00:04:29,700 We have used a function called 'range()', and this is technically a generator. 89 00:04:29,700 --> 00:04:34,400 And so 'range', when you give it numbers such as 0 and 100, 90 00:04:34,400 --> 00:04:36,500 it doesn't store all of this in a list. 91 00:04:36,520 --> 00:04:38,290 And we can even hit 'Enter' here, 92 00:04:38,290 --> 00:04:42,500 and it's going to say it's a 'range', because it is a built-in Python type. 93 00:04:42,520 --> 00:04:44,530 But this is a generator behind the scenes. 94 00:04:44,530 --> 00:04:49,500 It doesn't care that it needs to store 0-1-2-3-4-5 all the way up to 100. 95 00:04:49,500 --> 00:04:51,400 It just says, "Oh, you want to start with 0. Okay.", 96 00:04:51,410 --> 00:04:53,680 and then when you get to the next iteration, it says 1, 97 00:04:53,940 --> 00:04:55,770 and then 2, and then 3. 98 00:04:55,780 --> 00:04:58,770 And again, it doesn't care that it goes up to 100. 99 00:04:58,780 --> 00:05:01,740 Eventually it will get up to 100 and say, "Oh, that's it. 100 00:05:01,750 --> 00:05:02,820 And there's nothing left. 101 00:05:02,820 --> 00:05:04,300 So exit". 102 00:05:04,300 --> 00:05:06,700 So let's go ahead and create an example. 103 00:05:07,300 --> 00:05:10,600 Let's create a function that's going to multiply a number by 4. 104 00:05:10,600 --> 00:05:12,900 So a very, very simple example. 105 00:05:13,700 --> 00:05:14,900 We're going to say 'times_four', and 106 00:05:14,900 --> 00:05:18,000 it's going to take a number. In here 107 00:05:18,000 --> 00:05:20,500 we're going to have 'result = []', a list, 108 00:05:20,540 --> 00:05:23,970 and then let's loop through every number for that number. 109 00:05:23,980 --> 00:05:30,660 So 'for x in range(n)', and then in here we're going to say 'result', 110 00:05:31,200 --> 00:05:36,600 'result.append(n*4)', 111 00:05:36,600 --> 00:05:40,300 and at the end we're going to say 'return result'. 112 00:05:40,900 --> 00:05:44,600 Now here we can use this. Let's say I don't know, 'totals', 113 00:05:44,680 --> 00:05:45,700 or all the numbers, 114 00:05:45,710 --> 00:05:49,840 let's say 'numbers' is going to be 'times_four', and it's going 115 00:05:49,840 --> 00:05:51,400 to go all the way up to 100. 116 00:05:51,400 --> 00:05:53,500 And let's see what 'numbers' is. 117 00:05:54,300 --> 00:05:55,400 And I did something wrong, 118 00:05:55,400 --> 00:05:58,410 there shouldn't be 'n*4', it should be 'x*4'. 'for' 119 00:05:58,410 --> 00:05:59,800 item 'in range'. 120 00:05:59,800 --> 00:06:02,200 So let's go ahead and rerun these cells. There we go. 121 00:06:02,200 --> 00:06:06,400 So it starts off at 0, 0*4 is 0; and goes all the way, 122 00:06:06,400 --> 00:06:08,500 that's a lot, up to 123 00:06:09,500 --> 00:06:13,600 99*4 is 396. 124 00:06:15,100 --> 00:06:17,000 And so it did actually give us 100 numbers here, 125 00:06:17,000 --> 00:06:18,000 the 'range' function did 126 00:06:18,000 --> 00:06:20,600 at least. It started with 0 and went up to 99. 127 00:06:20,600 --> 00:06:23,400 So if you count all those numbers, including number 0, that is 100. 128 00:06:23,400 --> 00:06:26,800 Now let's go ahead and print this so that we can get a slightly 129 00:06:26,840 --> 00:06:27,910 more condensed view here. 130 00:06:28,900 --> 00:06:33,400 Now, what we can do is we can say 'for num in numbers: print( 131 00:06:33,450 --> 00:06:38,100 num)'. And you can see that it's going through every number 132 00:06:38,100 --> 00:06:39,900 one at a time. 133 00:06:39,940 --> 00:06:43,450 So now because we really only need each number one at a time, 134 00:06:43,450 --> 00:06:45,600 we don't need this whole entire list, 135 00:06:45,600 --> 00:06:47,300 we just need to do something one at a time here, 136 00:06:47,380 --> 00:06:50,640 this is a really good candidate for a generator, because 137 00:06:50,650 --> 00:06:54,420 when we're on the number 4, we don't need to know what's 138 00:06:54,420 --> 00:06:59,200 happening with 396, or 200, or anything beyond 4 really. 139 00:06:59,220 --> 00:07:02,010 And if that's ever the case in your code, a generator is 140 00:07:02,010 --> 00:07:04,400 a good candidate instead of just a regular list. 141 00:07:04,400 --> 00:07:08,200 And the reason here again is because this is storing all of this in memory. 142 00:07:08,240 --> 00:07:12,340 So if I did a search for 196, Python would be able to find 143 00:07:12,350 --> 00:07:15,160 it because it knows that all these numbers exist. In a generator, 144 00:07:15,160 --> 00:07:16,600 that's not so much the case. 145 00:07:16,660 --> 00:07:19,909 So actually, what I'm going to do is make this example just 146 00:07:19,909 --> 00:07:21,100 a tad smaller here, 147 00:07:21,100 --> 00:07:23,300 [no audio] 148 00:07:23,300 --> 00:07:25,600 just so this doesn't scroll down for days and days. 149 00:07:25,600 --> 00:07:28,000 [no audio] 150 00:07:28,000 --> 00:07:32,500 Now, one thing I want to point out here is 'times_four', 151 00:07:32,500 --> 00:07:35,400 let's go ahead and just write 'times_four'. 152 00:07:35,400 --> 00:07:38,200 That's the function name, and it comes back as a function. 153 00:07:38,200 --> 00:07:41,900 So that's good to, no, just put that in the back of your mind 154 00:07:41,930 --> 00:07:44,110 for a quick second, we're going to reference that in a little bit. 155 00:07:44,120 --> 00:07:46,420 Next, let's actually create a proper generator. 156 00:07:46,420 --> 00:07:50,400 So 'def times_four', it's just going to be the same name. 157 00:07:50,460 --> 00:07:57,440 It's going to take a number, and 'for x in range(n)', instead 158 00:07:57,440 --> 00:08:01,000 of returning, or instead of adding, whatever 159 00:08:01,000 --> 00:08:04,200 'n*4' is going to be, instead of adding that to a 160 00:08:04,200 --> 00:08:06,800 list, we are simply going to say 'yield', 161 00:08:06,800 --> 00:08:09,900 [no audio] 162 00:08:09,900 --> 00:08:13,100 And when I type 'times_four' this time, you'll see that Python 163 00:08:13,150 --> 00:08:15,170 still thinks that it's a function. 164 00:08:15,180 --> 00:08:18,020 Technically it is. 'def' means it's a function. 165 00:08:18,020 --> 00:08:23,600 But if we run this 'times_four', and let's put the number 5 in there, 166 00:08:25,300 --> 00:08:27,200 look at that. It's a generator 167 00:08:27,240 --> 00:08:30,960 now. Let's rerun the cells real quick. Just because we've 168 00:08:30,960 --> 00:08:34,100 got an overlapping name there, and you can see that this is just a list. 169 00:08:34,100 --> 00:08:35,900 This just returns a regular list. 170 00:08:35,940 --> 00:08:40,440 But down here, if we rerun these, it's a generator. 171 00:08:40,440 --> 00:08:45,400 Now, what that means is we can do for num in times_four', 172 00:08:45,400 --> 00:08:47,100 and then we can give it any number we want. 173 00:08:47,100 --> 00:08:51,500 So let's give it 10, print the number. 174 00:08:51,559 --> 00:08:53,860 And I did something wrong again. 175 00:08:53,870 --> 00:08:55,539 I made that same mistake earlier as well. 176 00:08:56,000 --> 00:08:57,000 Classic. 177 00:08:57,000 --> 00:08:59,200 [no audio] 178 00:08:59,200 --> 00:09:03,200 And so this looks the exact same as our initial example, 179 00:09:03,290 --> 00:09:06,080 but behind the scenes, it's only calculating one at a time. 180 00:09:06,080 --> 00:09:08,600 It's not calculating all of them. It's a generator. 181 00:09:08,600 --> 00:09:10,600 So it's gonna say calculate the first one, then the second one, 182 00:09:10,640 --> 00:09:12,820 then the third one, and then the fourth one, and so on and so 183 00:09:12,820 --> 00:09:14,600 on and so on until it gets to the very end. 184 00:09:14,600 --> 00:09:16,970 So let's go ahead and run an example here. 185 00:09:16,980 --> 00:09:20,120 Let's turn this into a variable, and let's call it 'numbers'. 186 00:09:21,140 --> 00:09:26,020 'numbers =', the function which is a generator, 187 00:09:26,020 --> 00:09:29,400 and it's going to times all the numbers up to the number 10 by 4. 188 00:09:29,400 --> 00:09:31,300 And we're going to loop through all these, and that will be fine. 189 00:09:32,200 --> 00:09:33,400 Gives us the exact same answers. 190 00:09:33,490 --> 00:09:37,440 And if we run 'numbers' in here, it's a generator. 191 00:09:37,440 --> 00:09:40,600 Now, what happens if we try to run this a second time? 192 00:09:40,680 --> 00:09:44,400 It doesn't matter what I do here, nothing shows up. 193 00:09:44,410 --> 00:09:48,780 And that's because this list, this generator has been exhausted. 194 00:09:48,790 --> 00:09:49,920 We ran it once here. 195 00:09:49,920 --> 00:09:51,150 We cannot run it again. 196 00:09:52,600 --> 00:09:55,300 In order for us to get 'numbers' again, we have to run this 197 00:09:55,300 --> 00:09:56,600 function again. 198 00:09:57,400 --> 00:10:02,000 So let's go ahead and talk about 'next', and 'iter'. 'Next', and 'Iter'. 199 00:10:03,400 --> 00:10:06,200 There are two really useful functions when it comes to generators, 200 00:10:06,350 --> 00:10:08,690 and honestly, you're probably not going to use these too 201 00:10:08,700 --> 00:10:11,900 often unless you really start working with generators day in and day out. 202 00:10:11,920 --> 00:10:16,000 However, if that does happen to be the case, these two functions 203 00:10:16,010 --> 00:10:17,530 are going to be very, very useful. 204 00:10:17,540 --> 00:10:18,760 So the first one is 'Next'. 205 00:10:18,770 --> 00:10:22,920 And I think a good way of sort of explaining this one is 206 00:10:22,920 --> 00:10:23,900 just with an example. 207 00:10:24,480 --> 00:10:26,550 So let's create a new generator. 208 00:10:26,550 --> 00:10:30,800 'def simple_generator', and it's going to take some sort of number, 209 00:10:30,800 --> 00:10:32,800 [no audio] 210 00:10:32,800 --> 00:10:36,700 and we're going to say 'for num in range(n): 211 00:10:36,700 --> 00:10:38,600 [no audio] 212 00:10:38,600 --> 00:10:39,600 yield n'. 213 00:10:39,670 --> 00:10:42,220 And so actually, this is not really doing anything. 214 00:10:42,230 --> 00:10:45,700 All it's going to do is create a generator that gives us 215 00:10:45,710 --> 00:10:46,840 like, 1-2-3. 216 00:10:46,850 --> 00:10:50,140 So this is a useless example, but we're going to see how 217 00:10:50,140 --> 00:10:51,900 we can use the 'next' function. 218 00:10:51,900 --> 00:10:57,300 So let's say 'gen = simple_generator', and 219 00:10:57,300 --> 00:10:58,300 let's just give it 3. 220 00:10:58,300 --> 00:11:00,300 [no audio] 221 00:11:00,300 --> 00:11:02,500 Now we can say 'print(next(gen))', 222 00:11:02,540 --> 00:11:04,370 and this is going to get the first one. 223 00:11:04,380 --> 00:11:06,800 And that actually should have been 'num'. 224 00:11:06,800 --> 00:11:08,330 I keep making that mistake today. 225 00:11:08,340 --> 00:11:10,520 My brain is just not working at the moment. 226 00:11:12,100 --> 00:11:13,100 So here we go. 227 00:11:13,100 --> 00:11:16,500 The first one says 0, and now it's going to run that next 228 00:11:16,520 --> 00:11:19,060 iteration, which is 1, and then, 229 00:11:20,050 --> 00:11:27,260 and then interesting, it only had 0, 1 and 2 in its instruction 230 00:11:27,270 --> 00:11:29,810 booklet. It didn't know what to do when it got to the number 231 00:11:29,820 --> 00:11:31,130 3, so it actually errored out. 232 00:11:32,100 --> 00:11:36,600 Now in the examples up here, it didn't error out for us, 233 00:11:36,600 --> 00:11:38,900 and that's because that exception is actually caught for us 234 00:11:38,900 --> 00:11:40,000 inside of the for loop, 235 00:11:41,400 --> 00:11:43,700 so Python handles that for us already, which is actually 236 00:11:43,700 --> 00:11:46,300 really, really nice. Thank you, Python, for doing that for us. 237 00:11:46,300 --> 00:11:48,910 So the 'next' function is just going to let you get that next 238 00:11:48,910 --> 00:11:51,100 iteration. Next, 239 00:11:51,100 --> 00:11:55,900 let's take a look at 'iter', and I'm saying 'iter' as 'I-T-E-R'. 240 00:11:56,900 --> 00:12:00,400 Now, this one is interesting because this introduces a new 241 00:12:00,880 --> 00:12:05,420 fundamental concept in Python and a lot of programming languages. 242 00:12:05,430 --> 00:12:09,500 It introduces this idea of an iterable versus an iterator. 243 00:12:09,840 --> 00:12:13,260 So an iterable simply means you can loop over something. 244 00:12:13,460 --> 00:12:15,170 Loops, tuples, strings, 245 00:12:15,180 --> 00:12:16,250 those are iterables. 246 00:12:16,900 --> 00:12:22,400 An iterator is an object which is used to actually loop over 247 00:12:22,700 --> 00:12:27,300 the iterable. So this is what makes something loopable, and this is just 248 00:12:27,300 --> 00:12:28,700 something that can be looped. 249 00:12:28,700 --> 00:12:30,770 Now, there is actually a difference in there. 250 00:12:30,780 --> 00:12:33,230 And I'm going to tell you right now, you probably don't need to 251 00:12:33,240 --> 00:12:37,460 know that this has only ever come up once in my Python 252 00:12:37,460 --> 00:12:41,060 career. So you probably don't need to know that unless you 253 00:12:41,070 --> 00:12:44,390 are in data science, and you need to constantly turn data 254 00:12:44,510 --> 00:12:46,000 into iterators. 255 00:12:46,010 --> 00:12:48,970 But nonetheless, if you are going down the data science route, 256 00:12:48,980 --> 00:12:51,490 machine learning, artificial intelligence, and anything like that, 257 00:12:51,500 --> 00:12:53,000 we should cover this anyways. 258 00:12:53,020 --> 00:12:55,870 So let's go ahead and create an example where we've got a 259 00:12:55,880 --> 00:12:59,080 'word', and let's just start with the word "Python", and we can 260 00:12:59,080 --> 00:13:02,000 do 'for letter in word: 261 00:13:02,600 --> 00:13:07,200 print(letter)', and we get P-Y-T-H-O-N. 262 00:13:07,900 --> 00:13:13,000 And if we try to run 'next(word)', we're actually going to 263 00:13:13,000 --> 00:13:16,300 see that it's a 'TypeError: 'str' object is not an iterator'. 264 00:13:16,300 --> 00:13:18,100 It's iterable, 265 00:13:18,100 --> 00:13:21,500 so we loop through this, but it's not an iterator. 266 00:13:21,500 --> 00:13:24,400 What we can do is we can convert this into an iterator. 267 00:13:25,900 --> 00:13:28,700 So we can say 'word = iter()', and then we can put the 268 00:13:28,700 --> 00:13:29,700 'word' in here; 'Python'. 269 00:13:29,700 --> 00:13:31,600 [no audio] 270 00:13:31,600 --> 00:13:33,500 And just for funsies let's see what this is. 271 00:13:34,900 --> 00:13:40,200 It's a string iterator, 'str_iterator', which means you can now use generator 272 00:13:40,200 --> 00:13:43,000 functions on it, so let's go ahead and type 'next(word)'. 273 00:13:43,900 --> 00:13:50,700 We'll get 'P'; 'next(word)', 'y', 't', 'h', 274 00:13:50,780 --> 00:13:56,150 'o', and 'n', and because it is exhausted, we saw this earlier 275 00:13:56,400 --> 00:13:58,400 it will throw us an error. 276 00:13:59,400 --> 00:14:01,700 Now, at this point in time, you're thinking, "Kalob, I don't 277 00:14:01,800 --> 00:14:05,900 really understand the difference between, like, a loop and a generator". 278 00:14:06,900 --> 00:14:10,400 Just ask yourself this, if you don't know when to use a regular 279 00:14:10,400 --> 00:14:11,900 list or a generator, 280 00:14:12,200 --> 00:14:13,200 just think. 281 00:14:13,200 --> 00:14:15,400 "Do I need to know all the answers right now? 282 00:14:15,420 --> 00:14:18,660 Do I need to store all the answers right now?" 283 00:14:18,670 --> 00:14:21,180 If you don't need to store this for later, and it's like a 284 00:14:21,190 --> 00:14:25,210 one time loop, a generator is probably a good use case for 285 00:14:25,220 --> 00:14:30,830 you. Now, what I would like you to do is go ahead, create 286 00:14:30,840 --> 00:14:32,450 a generator from scratch. 287 00:14:32,450 --> 00:14:34,500 It does not need to be complex. 288 00:14:34,500 --> 00:14:40,100 All it needs to do is 'yield' some sort of value in some sort of loop. 289 00:14:40,100 --> 00:14:41,500 [no audio]