WEBVTT 1 00:00:04.750 --> 00:00:08.680 in this video we're going to look at 2 00:00:06.580 --> 00:00:10.719 parts of generators and generator 3 00:00:08.680 --> 00:00:12.730 functions now because one of the 4 00:00:10.719 --> 00:00:14.950 advantages of generators is that they 5 00:00:12.730 --> 00:00:16.660 save memory and actually a lot of memory 6 00:00:14.950 --> 00:00:18.160 in many cases I'm going to start by 7 00:00:16.660 --> 00:00:20.980 showing how we check how much memory 8 00:00:18.160 --> 00:00:23.230 things use in Python so go ahead and 9 00:00:20.980 --> 00:00:26.380 create a new project and I'm going to 10 00:00:23.230 --> 00:00:29.860 call mine if I select the relevant 11 00:00:26.380 --> 00:00:34.239 things we're going to call it Jen 12 00:00:29.860 --> 00:00:45.249 example let's make sure in my case is in 13 00:00:34.239 --> 00:00:47.109 the right place and they're going to 14 00:00:45.249 --> 00:00:57.359 open a new file or rather create a new 15 00:00:47.109 --> 00:00:59.739 file and when I call this one sizes 5 ok 16 00:00:57.359 --> 00:01:05.920 so let's go ahead and type in some code 17 00:00:59.739 --> 00:01:09.250 we'll start by typing import this and a 18 00:01:05.920 --> 00:01:12.370 line three big underscore range is equal 19 00:01:09.250 --> 00:01:16.020 to range and a thousand in parentheses 20 00:01:12.370 --> 00:01:20.350 in line five with indoor print 21 00:01:16.020 --> 00:01:24.430 parentheses double quotes and Biggums 22 00:01:20.350 --> 00:01:30.190 called range is left and right curly 23 00:01:24.430 --> 00:01:32.800 braces space bytes in a dot format then 24 00:01:30.190 --> 00:01:35.320 within parentheses size dot gets sized 25 00:01:32.800 --> 00:01:37.180 off and then we type in big underscore 26 00:01:35.320 --> 00:01:41.380 range that's what we want to get the 27 00:01:37.180 --> 00:01:43.450 size from alright and that's the size 28 00:01:41.380 --> 00:01:45.310 before we've actually got some data in 29 00:01:43.450 --> 00:01:47.140 it now what we're going to do is on line 30 00:01:45.310 --> 00:01:51.670 seven we're going to create a list 31 00:01:47.140 --> 00:01:55.840 containing all the values so create a 32 00:01:51.670 --> 00:01:58.690 list containing all the values and we're 33 00:01:55.840 --> 00:02:00.580 going to put in ving underscore range so 34 00:01:58.690 --> 00:02:02.560 I'll start off by initializing a big end 35 00:02:00.580 --> 00:02:06.100 of score range equals in left or right 36 00:02:02.560 --> 00:02:09.580 square brackets and I'm going to type in 37 00:02:06.100 --> 00:02:12.940 for space val space in being on school 38 00:02:09.580 --> 00:02:17.170 range : and there's going to be big 39 00:02:12.940 --> 00:02:18.430 another school list sort of pins Val and 40 00:02:17.170 --> 00:02:20.859 actually that should have been big 41 00:02:18.430 --> 00:02:22.510 let's call list because we're using the 42 00:02:20.859 --> 00:02:24.849 range that we've defined on line three 43 00:02:22.510 --> 00:02:27.010 and we're creating this list which is 44 00:02:24.849 --> 00:02:32.079 containing all those values in that 45 00:02:27.010 --> 00:02:34.540 range like so and the last thing we'll 46 00:02:32.079 --> 00:02:37.480 do is let's just print out the size of 47 00:02:34.540 --> 00:02:39.730 the list so the little print parentheses 48 00:02:37.480 --> 00:02:43.000 double quote double quotes rather 49 00:02:39.730 --> 00:02:48.189 becomes called a list is a left-to-right 50 00:02:43.000 --> 00:02:51.459 curly braces then bytes then dot format 51 00:02:48.189 --> 00:02:53.709 and so I'm going to this dot get sizeof 52 00:02:51.459 --> 00:02:57.879 and I'm surprisingly big on the score 53 00:02:53.709 --> 00:02:59.980 list this time so there's our program so 54 00:02:57.879 --> 00:03:01.870 the part of the code itself creates two 55 00:02:59.980 --> 00:03:04.060 objects we've got two big underscore 56 00:03:01.870 --> 00:03:06.609 range that's a range that returns the 57 00:03:04.060 --> 00:03:08.439 numbers from 0 to 999 and it's not 58 00:03:06.609 --> 00:03:09.969 really that big a range but it'll do for 59 00:03:08.439 --> 00:03:11.980 our purposes here to demonstrate the 60 00:03:09.969 --> 00:03:13.659 memory usage you can make it bigger if 61 00:03:11.980 --> 00:03:15.340 you want but I'll wait until we run this 62 00:03:13.659 --> 00:03:17.319 program before using a larger number 63 00:03:15.340 --> 00:03:19.239 now a big underscore list on the other 64 00:03:17.319 --> 00:03:21.400 hand that object that is created by 65 00:03:19.239 --> 00:03:23.650 pending all the values from the bigger 66 00:03:21.400 --> 00:03:25.359 let's go range into a list and you can 67 00:03:23.650 --> 00:03:27.579 see the list being initialized on line 8 68 00:03:25.359 --> 00:03:30.129 then we then using to get sizeof 69 00:03:27.579 --> 00:03:32.349 function and eat in both cases from the 70 00:03:30.129 --> 00:03:35.489 sis module to see how much memory each 71 00:03:32.349 --> 00:03:39.340 object uses so I've actually run this 72 00:03:35.489 --> 00:03:42.099 you should find that they occupy 48 73 00:03:39.340 --> 00:03:45.760 bytes the range okay range itself as you 74 00:03:42.099 --> 00:03:47.049 can see occupies 48 bytes and the big 75 00:03:45.760 --> 00:03:49.720 underscore list though you can see 76 00:03:47.049 --> 00:03:52.599 that's taking up not nearly 9 kilobytes 77 00:03:49.720 --> 00:03:58.000 not a two-storey exactly the same values 78 00:03:52.599 --> 00:04:00.129 so I'll just move this down so I can get 79 00:03:58.000 --> 00:04:02.079 a better view down the bottom there if 80 00:04:00.129 --> 00:04:05.199 we go ahead and change and add an extra 81 00:04:02.079 --> 00:04:10.299 0 to the range up here on line 3 and 82 00:04:05.199 --> 00:04:13.449 then run it again you can see in this 83 00:04:10.299 --> 00:04:16.560 case the range itself is still only 48 84 00:04:13.449 --> 00:04:18.340 bytes but the list now is around 87 K 85 00:04:16.560 --> 00:04:20.259 hopefully there you can see why I 86 00:04:18.340 --> 00:04:22.990 suggested you wait before changing the 87 00:04:20.259 --> 00:04:24.430 actual numbers of values in the range if 88 00:04:22.990 --> 00:04:27.010 you make it too big you could eat up all 89 00:04:24.430 --> 00:04:28.360 your computer's memory now I should 90 00:04:27.010 --> 00:04:31.700 mention at this point that this isn't a 91 00:04:28.360 --> 00:04:34.280 very pythonic way of doing this and you 92 00:04:31.700 --> 00:04:36.770 probably use the list function itself to 93 00:04:34.280 --> 00:04:38.750 convert the range to a list but I wanted 94 00:04:36.770 --> 00:04:40.190 it to be obvious what we're doing which 95 00:04:38.750 --> 00:04:42.050 is why this code loops through the 96 00:04:40.190 --> 00:04:44.240 values in the range and appends each one 97 00:04:42.050 --> 00:04:46.160 to the list so what's actually going on 98 00:04:44.240 --> 00:04:48.770 here and how is it such a big difference 99 00:04:46.160 --> 00:04:50.690 in the memory that the two objects are 100 00:04:48.770 --> 00:04:53.480 using which actually is still exactly 101 00:04:50.690 --> 00:04:55.430 the same set of numbers well both big 102 00:04:53.480 --> 00:04:57.620 underscore range and Biggums call lists 103 00:04:55.430 --> 00:04:59.510 are actually iterators so we can use 104 00:04:57.620 --> 00:05:02.450 either in a for loop to iterate over all 105 00:04:59.510 --> 00:05:04.670 the values now big underscore range is a 106 00:05:02.450 --> 00:05:06.980 special case of an iterator called a 107 00:05:04.670 --> 00:05:09.170 generator and in fact we can run our own 108 00:05:06.980 --> 00:05:10.160 version of bigger than score range so 109 00:05:09.170 --> 00:05:11.990 I'm going to go ahead and do that 110 00:05:10.160 --> 00:05:14.510 and I'm going to call it my in the score 111 00:05:11.990 --> 00:05:17.500 range I'm going to go ahead up up here 112 00:05:14.510 --> 00:05:21.620 and start typing this code on line four 113 00:05:17.500 --> 00:05:24.650 so I'm going to define a function so def 114 00:05:21.620 --> 00:05:30.230 my own score range and in parentheses n 115 00:05:24.650 --> 00:05:34.910 colon and then int colon the end then we 116 00:05:30.230 --> 00:05:38.930 can have start equals zero while start 117 00:05:34.910 --> 00:05:41.000 is less than end colon then we're going 118 00:05:38.930 --> 00:05:47.200 to do yield type in the word yield space 119 00:05:41.000 --> 00:05:49.220 start and start space plus equals one 120 00:05:47.200 --> 00:05:50.690 and what we're going to do then is I'm 121 00:05:49.220 --> 00:05:53.870 going to comment out this next loan this 122 00:05:50.690 --> 00:05:55.400 bigger score range but was hard coded 123 00:05:53.870 --> 00:05:57.830 and we're going to change that to bigger 124 00:05:55.400 --> 00:06:01.130 than score range is equal to my 125 00:05:57.830 --> 00:06:02.840 underscore range and we're going to use 126 00:06:01.130 --> 00:06:04.250 the same number ten thousand so we're 127 00:06:02.840 --> 00:06:10.130 going to call the function that we've 128 00:06:04.250 --> 00:06:12.010 created so let's go ahead now and run 129 00:06:10.130 --> 00:06:17.900 the program again noting the previous 130 00:06:12.010 --> 00:06:19.490 values that we had down here and you can 131 00:06:17.900 --> 00:06:22.490 see in this case Big M is called ranges 132 00:06:19.490 --> 00:06:24.740 do eighty eight bytes and it may be 72 133 00:06:22.490 --> 00:06:26.570 by or something it's actually between 72 134 00:06:24.740 --> 00:06:28.940 to 80 eight bytes depending on the 135 00:06:26.570 --> 00:06:30.890 Python implementation point is that 136 00:06:28.940 --> 00:06:34.070 what's different 248 but it's still a 137 00:06:30.890 --> 00:06:35.270 vast improvement over 8k and that's 138 00:06:34.070 --> 00:06:36.830 because in this case of course we've 139 00:06:35.270 --> 00:06:38.780 written our own range instead of using 140 00:06:36.830 --> 00:06:40.010 the built-in one alright so I think I've 141 00:06:38.780 --> 00:06:41.930 made the point about the memory 142 00:06:40.010 --> 00:06:44.030 requirements so I'm going to reduce the 143 00:06:41.930 --> 00:06:45.260 range to just 5 otherwise I'm going to 144 00:06:44.030 --> 00:06:46.790 spend most of the time scroll 145 00:06:45.260 --> 00:06:48.230 and three thousands of lines of output 146 00:06:46.790 --> 00:06:49.490 that we're going to add so I'm going to 147 00:06:48.230 --> 00:06:53.570 go back here and just change the range 148 00:06:49.490 --> 00:06:56.240 to five Vanille and let's also now go 149 00:06:53.570 --> 00:06:58.430 ahead and actually print out the two 150 00:06:56.240 --> 00:07:00.470 objects at the end of the program so 151 00:06:58.430 --> 00:07:01.400 we've got the get sizeof function call 152 00:07:00.470 --> 00:07:03.110 which we're going to leave in there 153 00:07:01.400 --> 00:07:07.240 we're going to print this out as well as 154 00:07:03.110 --> 00:07:13.490 a little print be going to school range 155 00:07:07.240 --> 00:07:15.170 and print vegan school lists just to be 156 00:07:13.490 --> 00:07:18.110 consistent that's also changes commented 157 00:07:15.170 --> 00:07:21.890 out to range to five as well all right 158 00:07:18.110 --> 00:07:23.690 run it again so beginners called range 159 00:07:21.890 --> 00:07:25.430 in this case is eighty eight bytes 160 00:07:23.690 --> 00:07:27.410 bearing in mind that may be different on 161 00:07:25.430 --> 00:07:30.050 your operating system you might get a 162 00:07:27.410 --> 00:07:31.880 remember between 72 and 88 the point is 163 00:07:30.050 --> 00:07:34.100 it's the same as it was when I read last 164 00:07:31.880 --> 00:07:35.810 time and I'm surprisingly big on a 165 00:07:34.100 --> 00:07:38.420 school list is a lot smaller now because 166 00:07:35.810 --> 00:07:41.060 of storing fuel values in looking at the 167 00:07:38.420 --> 00:07:43.790 two lines of output that we've generated 168 00:07:41.060 --> 00:07:45.950 here down the bottom big underscore 169 00:07:43.790 --> 00:07:47.660 range is a generator object based on the 170 00:07:45.950 --> 00:07:49.730 Miami school range function that we 171 00:07:47.660 --> 00:07:52.610 wrote a big underscore list though as 172 00:07:49.730 --> 00:07:54.230 you can see is just a list and contains 173 00:07:52.610 --> 00:07:57.550 the values would expect from a range of 174 00:07:54.230 --> 00:08:00.620 five so what's the Miami school range 175 00:07:57.550 --> 00:08:02.330 function doing and what's this yield 176 00:08:00.620 --> 00:08:03.740 statement that we worked on on line 177 00:08:02.330 --> 00:08:04.550 seven what's that actually doing what's 178 00:08:03.740 --> 00:08:07.340 that all about 179 00:08:04.550 --> 00:08:09.770 well when you write a normal function 180 00:08:07.340 --> 00:08:12.290 the function finishes after returning 181 00:08:09.770 --> 00:08:16.700 the result you can see that if we change 182 00:08:12.290 --> 00:08:19.340 this yield and change that keyword to 183 00:08:16.700 --> 00:08:20.380 return and they get this warning here 184 00:08:19.340 --> 00:08:22.280 that the code is unreachable 185 00:08:20.380 --> 00:08:25.010 unsurprisingly because return is 186 00:08:22.280 --> 00:08:28.220 actually returning it the execution back 187 00:08:25.010 --> 00:08:29.720 to the calling code now if we go ahead 188 00:08:28.220 --> 00:08:32.510 and actually run that because that was 189 00:08:29.720 --> 00:08:35.120 just a warning we end up with an error 190 00:08:32.510 --> 00:08:37.820 the type error down the bottom there in 191 00:08:35.120 --> 00:08:40.310 object is not iterable that's because we 192 00:08:37.820 --> 00:08:43.010 can iterate over an int the point is 193 00:08:40.310 --> 00:08:45.980 that the - called range now returns a 194 00:08:43.010 --> 00:08:47.840 single value then stops as opposed to 195 00:08:45.980 --> 00:08:49.190 what it was returning before the other 196 00:08:47.840 --> 00:08:50.360 thing to note though down here you can 197 00:08:49.190 --> 00:08:52.850 see in the output the Bignell is called 198 00:08:50.360 --> 00:08:54.350 range there was only 24 bytes noting 199 00:08:52.850 --> 00:08:56.630 that the last few times I ran it it was 200 00:08:54.350 --> 00:08:58.639 88 and might have been a number between 201 00:08:56.630 --> 00:09:00.949 70 to 90 and in your operating 202 00:08:58.639 --> 00:09:02.480 the point is it's a different value to 203 00:09:00.949 --> 00:09:05.420 what it was when it was previously read 204 00:09:02.480 --> 00:09:07.279 so once that change in behavior to just 205 00:09:05.420 --> 00:09:09.319 return one value than stop there's 206 00:09:07.279 --> 00:09:12.199 something going on with the structure of 207 00:09:09.319 --> 00:09:14.449 the - called range object as well now 208 00:09:12.199 --> 00:09:16.910 when it's a generator and uses yield it 209 00:09:14.449 --> 00:09:19.399 actually takes up a bit more memory so 210 00:09:16.910 --> 00:09:22.970 we change line 7 again back to what it 211 00:09:19.399 --> 00:09:25.519 was to yield of course that warning goes 212 00:09:22.970 --> 00:09:27.829 that way the difference is that when we 213 00:09:25.519 --> 00:09:30.649 use yield the function actually returns 214 00:09:27.829 --> 00:09:33.559 the yielded value then goes into a sort 215 00:09:30.649 --> 00:09:36.619 of suspended state so it doesn't just 216 00:09:33.559 --> 00:09:38.540 return the value it keeps track of all 217 00:09:36.619 --> 00:09:41.360 its variables and worry about in its 218 00:09:38.540 --> 00:09:43.970 code it is so the next time it's called 219 00:09:41.360 --> 00:09:46.999 it wakes up and continues from where it 220 00:09:43.970 --> 00:09:49.610 left off so looking at this code on line 221 00:09:46.999 --> 00:09:51.110 12 this the function call 222 00:09:49.610 --> 00:09:53.929 you might be thinking it only gets 223 00:09:51.110 --> 00:09:56.749 called once but in fact it's called each 224 00:09:53.929 --> 00:09:59.779 time it's iterated over in the loop on 225 00:09:56.749 --> 00:10:01.699 line 18 down here and we can see that 226 00:09:59.779 --> 00:10:03.129 better by adding some diagnostic print 227 00:10:01.699 --> 00:10:05.660 statements so let's go ahead and do that 228 00:10:03.129 --> 00:10:09.679 so come up here to the - called range 229 00:10:05.660 --> 00:10:12.499 function let's add some code to print 230 00:10:09.679 --> 00:10:18.110 out so print parentheses double quote 231 00:10:12.499 --> 00:10:20.449 why underscore range starts and we'll 232 00:10:18.110 --> 00:10:22.249 also put one in the wild statement after 233 00:10:20.449 --> 00:10:23.689 the wild start to less than end 234 00:10:22.249 --> 00:10:25.850 statement or line 235 00:10:23.689 --> 00:10:29.410 then we'll do print parentheses double 236 00:10:25.850 --> 00:10:33.350 quotes my underscore range is returning 237 00:10:29.410 --> 00:10:37.879 and left the right curly braces dot the 238 00:10:33.350 --> 00:10:40.660 format's then start and if we actually 239 00:10:37.879 --> 00:10:43.189 run this and have a look at the output 240 00:10:40.660 --> 00:10:45.019 you can actually see that in that case 241 00:10:43.189 --> 00:10:47.480 my underscore range starts then we're 242 00:10:45.019 --> 00:10:51.019 getting a value 0 1 2 3 4 so katie has 243 00:10:47.480 --> 00:10:53.119 been called five times now it doesn't 244 00:10:51.019 --> 00:10:55.459 quite show the full story though now I 245 00:10:53.119 --> 00:10:57.739 said you might think that my underscore 246 00:10:55.459 --> 00:10:59.869 range is only called once or what was 247 00:10:57.739 --> 00:11:02.059 line 12 which is down line 14 over here 248 00:10:59.869 --> 00:11:04.819 but it's not actually called on that 249 00:11:02.059 --> 00:11:07.639 line so to see what's really going on a 250 00:11:04.819 --> 00:11:09.319 bit better we can pause the program by 251 00:11:07.639 --> 00:11:11.360 getting it to wait for input at various 252 00:11:09.319 --> 00:11:12.350 points so let's go ahead and do that and 253 00:11:11.360 --> 00:11:14.270 that should 254 00:11:12.350 --> 00:11:16.850 feels a little bit clearer so I'm going 255 00:11:14.270 --> 00:11:23.110 to go back up here onto line 12 and I'm 256 00:11:16.850 --> 00:11:25.220 going to put underscore equals input and 257 00:11:23.110 --> 00:11:28.930 parenthesis and the double quotes line 258 00:11:25.220 --> 00:11:32.090 12 they're going to come down to line 15 259 00:11:28.930 --> 00:11:33.830 let's take a copy of that line 12 paste 260 00:11:32.090 --> 00:11:38.180 it in for line 15 and then we'll change 261 00:11:33.830 --> 00:11:40.210 the reference to line 15 and make sure 262 00:11:38.180 --> 00:11:43.250 that we've deleted the extra line there 263 00:11:40.210 --> 00:11:45.430 let's also add a third one we'll come 264 00:11:43.250 --> 00:11:50.570 down here after the big underscore list 265 00:11:45.430 --> 00:11:54.020 let's go ahead and do that to line 22 so 266 00:11:50.570 --> 00:11:55.880 line 22 then lastly within the for loop 267 00:11:54.020 --> 00:11:58.880 itself let's actually put one in there 268 00:11:55.880 --> 00:12:03.710 so that's going to be line 24 so I'm 269 00:11:58.880 --> 00:12:04.490 going to make that line 20 for it just 270 00:12:03.710 --> 00:12:08.290 to be clear 271 00:12:04.490 --> 00:12:11.420 we'll add some extra text inside loop 272 00:12:08.290 --> 00:12:16.160 okay so we're using an underscore by the 273 00:12:11.420 --> 00:12:18.290 way aligns 12 15 22 and 24 that's of 274 00:12:16.160 --> 00:12:20.180 using that as a variable name in here 275 00:12:18.290 --> 00:12:21.800 because that's a Python convention and 276 00:12:20.180 --> 00:12:24.170 indicates that we're not interested in 277 00:12:21.800 --> 00:12:25.430 the value of the variable what we're 278 00:12:24.170 --> 00:12:27.020 doing is we're just using those input 279 00:12:25.430 --> 00:12:29.450 statements to get the program to wait 280 00:12:27.020 --> 00:12:31.820 until we press ENTER now if you're also 281 00:12:29.450 --> 00:12:34.010 programming in Java don't use a single 282 00:12:31.820 --> 00:12:36.140 underscore as a variable name in Java 283 00:12:34.010 --> 00:12:38.480 and stop doing it if you currently are 284 00:12:36.140 --> 00:12:40.940 now it's valid in Java right but it's 285 00:12:38.480 --> 00:12:42.830 being removed in Java and on though it's 286 00:12:40.940 --> 00:12:44.360 an accepted convention in Python it 287 00:12:42.830 --> 00:12:46.550 doesn't translate well to rid 288 00:12:44.360 --> 00:12:48.530 practically all other languages alright 289 00:12:46.550 --> 00:12:50.540 so now that we've added those input 290 00:12:48.530 --> 00:12:55.430 lines let's actually run the program to 291 00:12:50.540 --> 00:12:57.740 see how it behaves now okay so we're 292 00:12:55.430 --> 00:12:59.510 down here we've got tired waiting on 293 00:12:57.740 --> 00:13:01.790 line 12 and you can see there's no 294 00:12:59.510 --> 00:13:03.200 output at this point just waiting until 295 00:13:01.790 --> 00:13:06.200 the end of is pressed so when I press 296 00:13:03.200 --> 00:13:07.700 ENTER it's come back and said it's 297 00:13:06.200 --> 00:13:10.820 stoppable it's actually stopped again on 298 00:13:07.700 --> 00:13:13.340 line 15 so the big range equals my 299 00:13:10.820 --> 00:13:15.680 underscore range here in line 14 well 300 00:13:13.340 --> 00:13:17.510 that's already been executed but notice 301 00:13:15.680 --> 00:13:19.940 that nothing else is printed at this 302 00:13:17.510 --> 00:13:22.520 stage just the input prompt so in other 303 00:13:19.940 --> 00:13:24.470 words - call range the function hasn't 304 00:13:22.520 --> 00:13:25.850 been executed at this point so you 305 00:13:24.470 --> 00:13:28.250 wouldn't normally include this line in 306 00:13:25.850 --> 00:13:30.860 code you just use my underscore range 307 00:13:28.250 --> 00:13:32.209 five in the four loop in other words 308 00:13:30.860 --> 00:13:33.829 this is sort of an extra line there you 309 00:13:32.209 --> 00:13:36.230 just go straight down to here and you 310 00:13:33.829 --> 00:13:39.529 put my underscore range there on line 23 311 00:13:36.230 --> 00:13:41.269 direct in the four loop itself we've got 312 00:13:39.529 --> 00:13:43.370 it here so you can check the size of the 313 00:13:41.269 --> 00:13:46.220 object but it's really not necessary and 314 00:13:43.370 --> 00:13:48.500 in fact it can even be a bad idea and 315 00:13:46.220 --> 00:13:50.329 I'm going to show you why shortly now if 316 00:13:48.500 --> 00:13:53.870 I just continue on though back in the 317 00:13:50.329 --> 00:13:56.060 run window if I press ENTER again you 318 00:13:53.870 --> 00:13:58.009 can see it stopped on line 22 just 319 00:13:56.060 --> 00:13:59.990 before the for loop starts but now it 320 00:13:58.009 --> 00:14:04.009 gets interesting we press ENTER again 321 00:13:59.990 --> 00:14:05.420 and we've entered the for loop now you 322 00:14:04.009 --> 00:14:08.180 can see that this was the first time 323 00:14:05.420 --> 00:14:10.639 looking at the output that my own score 324 00:14:08.180 --> 00:14:12.860 range gets called when the first value 325 00:14:10.639 --> 00:14:15.199 is actually needed so we get the message 326 00:14:12.860 --> 00:14:16.699 my underscore range starts which of 327 00:14:15.199 --> 00:14:19.040 course we put up a start on the function 328 00:14:16.699 --> 00:14:21.670 and the first value in this case is zero 329 00:14:19.040 --> 00:14:24.380 is return so pressing enter again and 330 00:14:21.670 --> 00:14:25.759 the next fill is returned and notice 331 00:14:24.380 --> 00:14:28.130 that my own score range doesn't start 332 00:14:25.759 --> 00:14:30.980 again at the beginning it's continuing 333 00:14:28.130 --> 00:14:32.600 from line eight so you can see light on 334 00:14:30.980 --> 00:14:34.730 the screen there so we don't get the 335 00:14:32.600 --> 00:14:36.649 start message printed again now each 336 00:14:34.730 --> 00:14:39.019 time I press ENTER the next value is 337 00:14:36.649 --> 00:14:41.029 returned until the generator runs out of 338 00:14:39.019 --> 00:14:44.360 valleys to return and the loop axis and 339 00:14:41.029 --> 00:14:46.670 I'll just go ahead and do that and you 340 00:14:44.360 --> 00:14:48.410 can see our program is now all closed so 341 00:14:46.670 --> 00:14:51.620 the loop went around five times so the 342 00:14:48.410 --> 00:14:54.170 line 24 inside loop prompt was displayed 343 00:14:51.620 --> 00:14:56.329 five times all right so let's end the 344 00:14:54.170 --> 00:14:58.069 video here in the next video we'll go 345 00:14:56.329 --> 00:15:01.009 ahead and start talking more about this 346 00:14:58.069 --> 00:15:02.689 generator and add some extra code to 347 00:15:01.009 --> 00:15:06.009 this method to clear things up so I'll 348 00:15:02.689 --> 00:15:06.009 see you in the next video.