TubeSum

Python Nugget Problem & itertools — Step-by-Step Guide & Transcript

Chicken Nuggets and itertools - Python Basics with Sam

0h 59m video Published Oct 6, 2020 Transcribed Aug 10, 2026 F freeCodeCamp.org
Beginner 10 min read For: Beginner Python programmers looking to practice loops and learn the itertools module.
AI Trust Score 70/100
⚠️ Average / Some Fluff

"Delivers exactly what the title promises: a hands-on Python session on the nugget problem and itertools, though with some casual filler."

AI Summary

In this Python Basics stream, Sam tackles the classic Chicken Nuggets problem—finding combinations of 6, 9, and 20-piece nugget boxes to reach a target total—using nested for loops. He then introduces the itertools module, demonstrating chain, combinations, and count with practical examples, and shares advice on building a programming toolbox and learning effectively.

[02:33]
The Chicken Nuggets Problem

The challenge is to find combinations of 6, 9, and 20-piece nugget boxes that sum to a target number, starting with 50. The problem tests nested loop logic and combination generation.

[04:58]
Thinking Like an Odometer

Sam explains the approach: cycle through 6s (0-9), then increment 9s, and after 10 cycles of 9s, increment 20s. This mimics an odometer or clock, forming the basis for nested for loops.

[08:56]
Setting Up Variables and Loops

He sets up variables for the package sizes (6, 9, 20) and uses three nested for loops (i, j, k) to iterate through possible counts. The total is calculated as i*20 + j*9 + k*6.

[13:05]
Testing and Finding the Threshold

The program tests totals from 0 to 100, using try/except to catch cases with no solution. The result: all totals from 44 upward can be formed, with 43 being the last impossible number.

[28:43]
Introduction to itertools

Sam imports itertools and explores its methods. He highlights chain, combinations, and count as key tools for solving problems more elegantly than manual loops.

[31:19]
Using chain

chain links multiple iterables into one sequence. Example: for i in chain('xyz', 'abc') iterates through all characters. It can take an endless number of iterables.

[37:49]
Using combinations

combinations(iterable, r) generates all r-length combinations without duplicates. Example: combinations('abcdefg', 3) yields 35 combinations. Aliasing (import combinations as com) is shown.

[45:53]
Using count

count(start, step) creates an infinite counter. Unlike generators, it never exhausts. Example: count(1) then next(x) returns 1, then 2, etc. Useful for numbering without manual tracking.

[50:08]
Building a Number Pyramid

Sam demonstrates a pyramid pattern using count and nested loops. He explains the end parameter in print: default is newline, but setting end=' ' or end='' suppresses it to keep output on the same line.

[55:02]
Final Advice for Learners

Sam emphasizes: never delete code—comment, save, archive. Make notes for future clarity. Ask questions, join communities, and fill your toolbox with new skills. Solve problems repeatedly to improve.

Mentioned in this Video

Tutorial Checklist

1 08:56 Define variables for package sizes: 20, 9, 6.
2 10:58 Create three nested for loops: for i in range(10), for j in range(10), for k in range(10).
3 15:21 Calculate total as i*20 + j*9 + k*6.
4 18:39 Store combinations in a dictionary with total as key and (i, j, k) as value.
5 19:35 Break out of loops when total equals target (ttl).
6 20:47 Print the combination using f-string formatting with triple quotes.
7 25:27 Test for a range of totals (0-100) using try/except to catch no-result cases.
8 31:19 Import itertools and use chain to link iterables.
9 37:49 Use combinations(iterable, r) to generate all r-length combinations.
10 45:53 Use count(start, step) for an infinite counter, calling next() to advance.

Study Flashcards (9)

What are the three package sizes in the Chicken Nuggets problem?

easy Click to reveal answer

6, 9, and 20.

02:33

What is the smallest total number of nuggets that can be formed from 6, 9, and 20?

easy Click to reveal answer

6 (one 6-piece box).

26:38

From what number upward can every total be formed using 6, 9, and 20?

medium Click to reveal answer

44.

26:50

What is the largest total that cannot be formed using 6, 9, and 20?

medium Click to reveal answer

43.

27:04

What does the itertools.chain function do?

easy Click to reveal answer

It links multiple iterables into a single sequence.

33:16

How many combinations of 3 letters are there from a 7-letter iterable?

medium Click to reveal answer

35.

43:00

What does the itertools.count function do?

medium Click to reveal answer

It creates an infinite counter that starts at a given value and increments by a step.

46:05

What is the default value of the 'end' parameter in Python's print function?

easy Click to reveal answer

A newline character.

52:51

What does setting end='' in a print statement do?

easy Click to reveal answer

It suppresses the newline, keeping output on the same line.

52:36

💡 Key Takeaways

📊

Threshold Discovery

Reveals a key mathematical insight: all totals from 44 upward are possible, which is the core result of the nugget problem.

26:50
💡

Infinite Counter Concept

Explains a fundamental difference between count and typical generators—count never exhausts, which is a powerful tool for numbering.

46:05
⚖️

Never Delete Code

A practical learning principle: keep old code and notes to track progress and aid future understanding.

55:02
⚖️

Fill Your Toolbox

Encourages continuous skill acquisition and revisiting problems to improve, a core philosophy for programmers.

57:29

[00:13] let me mute everything else that we don't need all right this should be up let's see this should be up let's see got a good light streaming

[00:29] all right i forget how much of a delay there is let me know all right so i gotta click over

[00:42] here here we go all right look i got my shirt i was able to meet up with uh quincy a couple weeks ago we chatted had an awesome chat so want to say thank you to him and he got me a

[00:55] shirt and i told him i would wear it every stream but i realized i just have this zoomed in so apparently i'm gonna have to work with my webcam but hey all uh we have all these awesome contributors uh

[01:09] uh i spend uh all my time as volunteers so so if you guys could go down below and grab something a shirt a cup a hat should ask for a hat i should have

[01:21] thought about that maybe maybe i'll go on and buy a hat but uh just go down and support free code camp uh quincy and bo and his group are doing an amazing job all these everything here

[01:33] is uh 100 free and they are doing a great job and uh i want to help out as much as i can because like i said with the chat with quincy uh really kind of see

[01:46] just there we go all right so what in the world am i talking about about chicken nuggets and itter tools

[02:05] is chat back up and running i know i restarted everything let's see all right good cardinal is everything all right good cardinal is everything good

[02:17] could see you just one on one that might be an idea for next week so chicken nuggets so actually i stole this uh project from uh someplace else

[02:33] but the idea of the chicken nuggets is you have and it's from a very well-known they have combination of chicken nuggets of 6 9 and 20.

[02:45] and the challenge is the problem is uh for you to write a to take it started with started at least 50 and what we'll find out is we'll use the skills that we have um

[03:07] we have uh some awesome moderators and they'll make sure that what um uh

[03:19] gets through um so all right but i digress so the challenge was but i digress so the challenge was take i want 50 chicken nuggets what combinations of our six nine and 20 to get 50 and then really even

[03:34] sophisticated what happens if i wanted 53 chicken nuggets how would we go about that so let's just get into it and then what we'll find out is we'll we'll write a little bit more and we'll see how in the world

[03:48] can we get basically every combination and then we're going to look at a very awesome module uh itter tools all right so i got about an hour so let's just jump into it so if you guys are new here i'm sam from

[04:00] python basics uh supporting free code camp so make sure you're going and uh we're going through all the videos that i've already done so you can see down in the uh description below

[04:14] um anything that we're we've done here and you didn't quite get it there is a video for it alright so let's get at it nuggets i get

[04:28] i get all right first so we have oh i didn't even check can we see this i need to shrink that

[04:45] can we see this i need to shrink that didn't think about that boom so we have our combination we have six and we have 20. so how in the world are we going to do

[04:58] this we need to think about this like a did i keep the picture of the odometer i did i did or the flipping clock

[05:10] about this and how we're going to solve it and how we're going to lay it out and then how we need to design it let me make sure you can see so we have 6 we have 9 and 20. so we need to revolve

[05:26] through and as we get back to a certain number of combinations of one then we need to flip it over i was thinking about an odometer but then i was hard to flippy old-timey odometer than i thought about

[05:40] a bunch of things but i'm a lot older than most of you guys so um found this image of a clock so this is what we're going to do we gonna we're going to start with six so we go one two three

[05:54] five six seven eight nine ten then we're going to flip over to nine and then we're gonna and then we have to reset two three four five six seven eight nine ten

[06:07] flip over and then another one so what does that sound like the tools that we already have does anybody have any i have way too many um

[06:26] all right let's see this is cardinal you might be able to help me

[06:39] this is our 9th or 10th but you can also click down in the description of all these videos bo has done an awesome job of consolidating them but

[06:54] all right so basically this is how i want you to think about this this is nested for loops so we're just gonna pick an arbitrary 10 this at first we're going to go

[07:07] 10 6 combinations then flip over to 9. then we're going to do 10 more 6 combinations flip over to 9. then once we get to 10 9 combinations we're going to flip over to 20. then as we're doing this we're going to

[07:22] this we're going to check and see if this total are total because y is going to be our total number of chicken nuggets let's just do total let's change that i had y in my

[07:35] in my experiment so i probably need to change that to change that to two

[07:51] i got a couple y's in here because that will be confusing to you it makes perfect sense to me all right total and one more total so then we need to think about our challenge with our

[08:04] it so we're gonna i'm gonna just kind of walk you through so we're going to be taking all of these going to work a lot of them as we go through these

[08:18] at one point we're going to have one two three four so four if we have four combinations of six that's 24 and then two more uh 18s

[08:31] or two more nine which is 18. so 6 times 4 4 is 24 and then 9 times 2 is 18 18 and 24 that may not be any combination we want so we're gonna let

[08:44] our program sort through all of these for loops and go from there so all right let's get our let's get our layout

[08:56] these and see and it's good good practice and experience so basically our first general idea is we want to know how many combinations of these different chicken nugget

[09:10] packages to get 50 chicken nuggets that's our starting point all right so we need to get some variables going so we need to get some variables going so we got 10 or excuse me uh 20

[09:23] 9 and 6. so 20 and 6. let me flip over here to chat make sure i'm not missing anything global great question all right

[09:37] a variable inside a function variable inside a function can be moved in and out because a variable by by default

[09:53] a variable by by default is a local variable if it's inside a a function and it typically cannot be pulled out so i wanted to do global so that when we are going and we want to test and look at our dictionary that has

[10:05] all these combinations we can just pull it out so that's what i'm doing right it out so that's what i'm doing right now

[10:17] thank thank you very much it is the 10th all right all right so cardinal is uh our mod um cardinal's been around a while uh been very helpful and has moved up and

[10:31] actually an admin on uh the python basics discord and also a moderator on this free code camp stream so just want to say

[10:44] camp stream so just want to say thank you as always to cardinal okay so we need to get a for loop going so we have combination values

[10:58] so we need to have three for loops to then go through and set up a function so each time through this iteration

[11:13] we need to then so um that math uh formula right there is use these because that variable's gonna just go

[11:28] through so that is exactly it so let's just get at it and then we're gonna look at some pretty cool stuff but this is just a great just a great thinking problem how in the world

[11:42] and move through all of these combinations to test it so for i 10 and this this was just my first hack my

[11:54] first attempt at checking this there are tons of better ways to do this i haven't looked at this since i first solved it because i know there's better ways but i have

[12:09] not wanted to test it until um we got together and to do this to see what actually comes out of it because there are much better ways all right so this is going to be our

[12:23] 20 nugget combination so that's our that's our outer that's like our um on our ring going around just like this so this we're going to cycle through our

[12:36] all the time we're gonna cycle through our nine loop every 10 times through and then we're going to cycle through our 20s every 100 times through does that make sense every

[12:52] time through so 10 10 go arounds then move up to here so basically this is our singles our tens and our 100s place all right okay so now then we go

[13:05] so now then we go and we're just nesting all of these for range 10 should get chat open that's just our test right now we're going to test for 50 to kind of wrap our

[13:20] threshold where below that a combination of these will not in the original instructions for this problem 50 and up works for every single

[13:32] one and then i'm gonna we're actually gonna use our skills that we have about um try and accept to see how low it can go to go from there so all right here is our that's our um

[13:47] nine combination and then now we're gonna do our hijk in range but yeah our first mental starting point is 50 so we know it'll work

[14:09] cardinal has instructions to just uh remove and then boot because we are here uh for learning purposes light like i said

[14:22] um all this is free um and we have best intentions in mind and we just wanna have a good clean supportive community all right thanks thanks cardinal all right so

[14:38] and see how in the world we need to do this so this is a little junky because again the i wanted to show you exactly my first attempt at this

[14:53] [Music] and that function that mathematical function actually has to keep saying function but if we look over i think somebody already threw it up but

[15:06] somebody already threw it up but it's going to be so it's in in order in in order so this is our 20 this is our nine this

[15:21] consistent so i times

[15:33] j times k times

[15:48] let's see k times s every time through i i times 20

[16:01] k times s all right so now we want to test this going back and i i peaked a little bit and i was like i need to exactly know so

[16:14] dictionary because i remember this was very similar to my first way that i solved our primes oh my goodness if you haven't seen that attempt at how to find a prime number on my first example

[16:33] yes tt is the total number of chicken nuggets that we are t ttl that we are wanting so we're going to input so our first attempt is going to be 50. so we are going to input nuggets 50 and we

[16:47] want to get out the number of nines how many sixes because i think what i originally did in

[17:00] this go round was i let it go through every single combination and then i sought out and then you could actually then see then see because you're going to see

[17:15] be over overloaded all this is is the python challenging uh for new people to find the right editor and feel like they're overwhelmed i just use shell when i'm doing when

[17:29] every single one of my tutorials it's the it's the python editor script and and then um the shell because that's sufficient thank you cardinal

[17:46] cook if we're not we're not gonna spam here okay so now here's my

[17:58] so now here's my thank you cardinal all right some uh issues for um where programs are and files are laid out for new people and pride charm can

[18:12] be very overwhelming and frustrating so if you have experience with pycharm you're very easily able to put this into your pycharm program so that that's that all right

[18:27] so that that's that all right so then i'm making so right here is i have my key value i'm putting these in and i want you then to be able to go back and look at all the combinations that are here so far

[18:39] so here's my key and then i'm going to be assigning the value and it's going to be my k where did i change this nope let's stay consistent i j

[18:51] k so what am i doing here so each time through it's going to get the total it's then going to write this key to this dictionary and we're going to see

[19:05] the values again i know this doesn't really have a again i know this doesn't really have a purpose right now but i have no problem showing you the absolute really ugly stuff that i did

[19:20] now what in the world am i doing here so then we got to come out here here break

[19:35] yep then if ttl equals total then break then break then

[19:53] know you can de-indent a region

[20:13] total equals tote anybody see my mistake i missed a equal sign so let's go through this real slow because i think we have probably quite a few new people

[20:34] yes we are going to print um but all right so break only moves you out one for loop so as we come through as we come through we need to kick out each single time

[20:47] so all right one two three one two three all right so now i need to now we're

[20:59] now we're gonna get some printing and this is yep all right

[21:32] y and

[21:47] didn't change it six piece

[22:02] mind so this is one this is zero and this is nine and this is 20. all right so i just realized i changed that last part didn't

[22:17] catch that so now when this reaches when this is reached our total our tote of our combinations of each of these matches this

[22:30] stop stop stop and then print out the combinations and i need to then come here and one two three close this out so why like this

[22:46] because i want this on multi lines so when i use my three quotation marks this is it's a multi-line um control of a print statement so this is my f string formatting and i want this

[23:01] my f string formatting and i want this to come go in to my to come go in to my that needs to be sorry ttl when this is here then out of my dictionary

[23:13] dictionary grab my key

[23:29] happens again this i wanted to show you how ugly my first attempt at this was sorry let's just run it uh oh actually we need to pass in

[23:53] is i said i want the total so there's my total that i pass in then i want to see what this placement is because i'm writing

[24:07] this to my dictionary i need five six piece and i need zero nine piece and i need one t one one t one twenty piece

[24:23] all right so let's pass in let's pass in a test to see so right now i told you 50 works about 49.

[24:41] piece okay that's pretty pretty pretty uh

[24:54] all right 47 how do we get that how do we get 47 so three three by s so three sixes a nine and a

[25:07] twenty piece all right so now we're just kind of hitting and missing kind of hitting and missing so now let's let's change this up

[25:27] this so right now if i go and i change

[25:40] range of numbers for i in range let's go 0 through 100. now we know 0 is going to throw an error

[25:54] now we know 0 is going to throw an error so let's just let's just try this i and humble append i

[26:08] i then accept i no results

[26:22] and i think i just changed that up on you guys so now where does this so of course zero zero zero so we can't find one two three four

[26:38] five but we can find six then we can't get seven eight nine i'll just show you but from if memory serves 44

[26:50] from 44 chicken nuggets to the end of time you can find any number of combinations so as you can see right here no results is the first

[27:04] as the last one at 43. you could even find 40 was it 39 blew me away so yeah you can have 39 and of course 36 is uh really simple it's just 6x6 but this was

[27:19] an absolutely awesome example yeah i wish i could speak uh other foreign languages my

[27:31] younger son is doing spanish and my older son he's he's been talking about trying to learn russian

[27:43] now let's get on to some cool very cool stuff we got 30 minutes if if if this gets buried um you can always just description down below and check this video out and i think i

[27:59] just to remind you guys it's been 30 minutes since i've done this make sure a shirt or a hat i should i think i'm going to buy a hat so i can have it on to buy a hat and sorry about the the dot on my face i'd forget it the time of

[28:15] year is changing i usually don't film this time of day so i need to hang something in front of hope it's not too disturbing for everybody other than my normal face being being

[28:27] being on the screen but all right uh let's see uh itter tools let's just get after it so what what is ittertools let's get down to the

[28:43] um import iter tools enter iter tools so here is a bunch of methods from itter tools so

[28:59] let's run help on iter tools 692 lines let's bring this over just a touch so we're going to go through some of them

[29:13] uh i think the one you'll like the most we're going to skip accumulate because i wasn't sure what our next topic was going to be but we are going to do operators because but we need to learn about operators before we can do

[29:27] accumulate that is a perfect example but um uh count we're going to do what we're going to do today uh if we do have if we have time we're going to look at chain

[29:39] we're going to look at a chain from iterable and then we're going to use the tools that we have to go over a suggested

[29:51] video that i had that i was able to tie these all together but if you guys are these all together but if you guys are new here um there was a lot of chatter about how to practice for loops and all of

[30:06] these things make sure you check out my video from yesterday about filling up your toolbox so that's why i'm probably most excited about this video or this stream today about itter tools because once you learn

[30:21] about itter tools because once you learn learn these things if you you you when you have a problem you want to make sure that you have a

[30:33] variety of tools instead of just walking around with one tool that you have and you keep trying to just use that hammer because everything will start to look like a nail that's an old old-timey carpenter saying

[30:49] so yeah here we go uh chain count yeah i i think count is probably one of the coolest and then we'll just let's comment all this out

[31:03] there's our stuff from two weeks ago all right all right so from so from itter tools

[31:19] chain so chain is a very cool one so does anybody not know what i just typed from intertools import chain so durr on editor tools

[31:35] so now so here's my module iter tools then here is iter tools then here is mine let's see if i can do my alphabet

[31:49] i wanted to run help on if i wanted to see the documentation for if i wanted to see the documentation for chain in my shell environment right here chain in my shell environment right here i have to do it or tools dot

[32:02] chain now with this keyword from now with this keyword from i jump into itter tools and i pull out so now when i run this i come over here

[32:15] so here's the documentation for itertools.change so the chain method in inside editor tools chain class inside module itertools now that i've done this

[32:28] i can just run help on chain so i've grabbed chain pulled this out and now this is a function boom just like this

[32:44] so now what let's see what in the world this does d e f e f

[33:00] z equals g h i had to cheat on my alphabet so for i in chain x y z

[33:16] so chain will literally link all these together together boom and then make a new

[33:28] and as we know we can iterate through an iterable and this just to wherever you'd like them to go now let's say we had these in

[33:44] a list x y and z throw this in a list now let's look at

[34:05] have chain and i run dir on chain and i run dir on chain so i'm one level inside of chain now this is one of the rare ones where a method then has a a

[34:21] all right is everybody following that

[34:39] very nice very very nice somebody already caught very very nice somebody already caught the um

[34:56] it can take an endless amount we use this on our uh good very good checks very good catch so now now that we throw this in

[35:15] now i throw it in an iterable a list so for i in chain dot

[35:28] iterable i could have just hit but i don't want to do that so then i pass it this and i go print i i get the same result

[35:41] result but if you already have a all right now we're getting close to some of my favorite ones all right

[36:07] i'd like to say that i'm very successful so i've been adding so uh down over on my page what you'll see is um i know the more recent ones current ones um

[36:23] no it's not better than pycharm it's just you don't need to do anything to it to run a the interpreter and runs it off here this is the bare

[36:37] bones i am here for new new new people to remove any concerns any fear any i'm i'm here to tear down the um

[36:51] the the any any any any fear or any um because a new person learning programming the likelihood of them running into a

[37:04] of any type slows them down from learning i want to show them how they can start solving and writing code with the littlest of get other software i'm here to teach them

[37:19] how to learn to program how to get success under their belt problems and learn about what interpreter they want or what editor they want to use okay all right so

[37:34] saw but no i'm not going to get into a discussion about what editor to use did it's that i'm here to show you guys uh how to program all right

[37:49] combinations from iter tools import import combinations

[38:08] so now now what now what did i do so now i got now i just told you what this was now i changed it and added this all right so i've thrown up another keyword called as that's called alias aliasing

[38:22] so i'm bringing this in but before we had chain brought in chain right here well now i don't have to type like if i did this and do it as c chain would be called c so now

[38:35] combinations is called com okay so now when i do c o and b it has been aliased referred to nicknamed

[38:48] c-o-m-b all right so cool that's what that is all right so cool that's what that is so now letters g all right

[39:03] saying that i'm not going to talk about editors editors i'll see a few people left

[39:19] okay all right was talking about github so i know on my very on my current videos that get published it has a link to my github i have a running file of the free code

[39:35] camp dot p y and then i also throw in the notes of the day from the shell so you can see everything that we typed live or ran it will be dated today's date always the

[39:49] current date and then the free code camp dot p y it might be just fcc dot p y it that is the running um extension and i add to it and i edit it every time after class

[40:07] uh right now what we're doing is we're running through um tools we just did we got done earlier uh this morning going through this morning going through a how to write a function to capture

[40:22] um uh chicken nugget combinations if i wanted 50 chicken nuggets how many combinations of each packaging quantity would i need so there we go that's that and then now we're on our

[40:35] third example or excuse me our third method for um intertools we're looking at combination and what we're going to do with combination is i want to see

[40:51] all right x i want to run combinations i want to run combinations of letters 3 so all right so what am i doing

[41:07] help on commv okay very good documentation here all right so it takes in two

[41:22] two arguments an iterable the quantity of the combinations from that interval so if i were to pass range three excuse me range four so that's

[41:39] three excuse me range four so that's zero one two three right then i want all i want all the combinations of three of those all right

[41:55] there we go so now to kind of that is can be a little much to see from in my experience so that's why our example is going to be so i want here's my

[42:10] here's my iterable it's seven letters and i want all the combinations of it's going to be this this this so let's just let's just do it so why and i'm

[42:22] going to print these out we're going to do list comprehension join i for i and x boom so this is making then another

[42:37] iterable of all the and i want to then join them and that's supposed to be dot uh now let's run this and see what in the world we get

[43:00] do there are 35 combinations so i want you to look at this so abc a b d

[43:16] e a b so we're here we're here right here a b f then a b g then it moves over ac and it's a c d

[43:29] see that so i have all i have this string i have an i have a string i have an interval and this iterable is a string and i want

[43:47] and python has this wonderful algorithm that goes through and goes okay you just want three of these and you want all the combinations of an assortment of these three which happens to be strings

[44:02] moves over and does the first two then it comes through and it skips over to c a and c say stay

[44:16] stay stationary then d e f and g as we can see we got here's here's a great example here's here's a great example so i want to show you so it's a c

[44:28] so a c and g then it moves over to a then it moves over to a d

[44:41] so boom boom boom so as it's going through because if it were to do any combination any other pattern than this it would have duplicates right so this shows you how

[44:55] to logically think about an assortment just like our combination and our wheel of flipping around like an odometer or a clock so all right it is 47 minutes after so it's time to make sure we're going down

[45:11] and buying a shirt a hat a cup i think there's a mouse pad something make sure there's a mouse pad something make sure we're supporting uh free code camp it is they're doing an absolutely awesome job all right

[45:24] all right okay we got 13 minutes let's see if we can fly through this because you guys i remember when i saw this one so now we're gonna do count who remembers next

[45:39] who remembers next yes you can watch this video after beau has this set up awesome thank thank you cardinal cardinal all right so from

[45:53] count all right what in the world does count do it's so cool

[46:05] or tools count help count count it's so neat wait a second what is this

[46:20] first first value zero it's equivalent start step so oh look at this we know a double underscore

[46:34] next means this means that when we create an object a count object we can use next on it and here is the awesome thing about count every other time we have a generator

[46:48] object and we use we use next it is exhausted right it has a stopping point so a generator object has limitations count does not it literally just starts you will never run out so all right

[47:03] let's just let's just look at this so count equals one i call i call x right

[47:22] so i still call x right x count stays one until i call next on it call next on x one but then it's done something now it's two

[47:35] they work together so if i want something to be counted and i don't want to have to keep up with it and i don't and i know i need to use next on it but i don't know where that ending is going to be

[47:48] like a list of customers a list of accounts i don't need it to end i don't want to have to go back and go oh my goodness kind of like what we did i doubt i doubt any of you remember but

[48:02] in 2000 uh we had an issue where all of the birthdays nobody thought we'd ever ever birthdays nobody thought we'd ever ever run into um 2000 so all of the birthdays

[48:15] run into um 2000 so all of the birthdays were basically built into 1900s so we had to go back and change everything so we set a limitation so now everything has been removed so this next is just like that

[48:31] is just like that so now when i call let's call x again x so now when i call let's call x again x stays there until i call next on it x is three and it just it just sits there and these work

[48:46] hand in hand so all right i think i got i got nine minutes let's see and then i gotta go i gotta i gotta get moving i got i got a lot i got a lot to do today so i hate that i hate that we only get an

[48:58] hour today but still and also probably gonna we're probably gonna be going to two weeks um

[49:11] okay chicken nugget problem christian let's see for the chicken nugget problem uh we'll have to cardinal make a note of that question right there from christian and see and

[49:27] help me remember to look at it because we got nine minutes i want to try to do different ascending so i was going through all the notes whenever i have so this

[49:39] was an awesome question that came up and it worked perfect and it worked perfect for inter tools if i remember yeah so how in the world could you do a number pyramid because here's a perfect

[49:53] number shapes especially uh pyramids triangles uh diamonds it's an outstanding exercise for for loop understanding

[50:08] so how how in the world could we do this using the tools that we have start

[50:20] equals oh we got to bring in our awesome toolkit so from iter tools

[50:34] so from iter tools import count so what what did did anybody notice what count does

[50:49] help count all right

[51:12] so start or count it takes a start and step step is the iteration so we want to go every two so we don't have to handle we don't have to handle the spaces we're going to use the tools that we just added another tool to our toolbox

[51:25] then our num is going to be count we're going to start at 1 count 1. all right so 4 i in range

[51:38] four then print this is one two three okay that looks right

[51:53] i forgot how convoluted this was and all right so what does n do

[52:05] anybody remember all right i know i'm flying through a lot so what does inside the print oh that's not right and that's ugly that is absolutely not right this needs

[52:18] another parenthesis there we go and we check that yep i got so what is my end equals uh empty string who wants to comment that puts it on the same line absolutely more correct it suppresses the ret the

[52:36] new line because the default for print shoot let me see yeah i think i got this sized right yeah i think i got this sized right the default argument for end is a new

[52:51] line every time python runs unless we change it it's going to return to a new line didn't pass anything new line moved down so when i do this

[53:10] actually i've never done this so this is why i love if i then suppress it i'm back to getting one line so this automatically gives me an empty line so when i pass it a empty line i

[53:26] get two because the default is so i pass an empty line new line and i suppress a new line i'm back to one line so cool this is why i like doing these same examples over and over and over again because it makes me think it makes me

[53:40] better so you guys the question is look this is super important if you guys have a question ask it even if you kinda or if it's question because somebody else doesn't know

[53:53] that information all right how do do for j in range next this is where it gets cool

[54:06] next this is where it gets cool next start print oops

[54:19] next num end and i need a space and i think there's one mistake in here i think it there i left it on purpose

[54:33] all right so we need to go so we need to go this is it right here assume so let's see what this does why why does this just run and

[54:47] taper off because i'm running through and i need to make sure that i have a starting point so there we go so all right

[55:02] well i think that is a great stopping point and but look you guys are asking a ton of good questions and i just want to again we got another 15 minutes went by just make sure we're supporting free code camp but look i

[55:16] just can't tell you guys this enough just keep programming just keep writing just keep asking questions there are a ton of ways and a ton of

[55:28] resources free code camp is a perfect example example my channel fills a gap of the micro video if you can't find something i promise you

[55:40] it it has a simple small video on my channel every single one of these topics has its own video the chicken nugget example it's its own video you can go

[55:52] through some people uh love these long formats other folks want these small things when they're working on a project and they can't remember or don't know and it's fine but don't ever delete anything if i

[56:05] can tell you that i wish i would have heard that forever ago when i was starting to learn to program don't ever delete anything comment it save it archive it however and also make notes

[56:20] in the side when i'm off here i go okay uh i go okay uh it's

[56:33] because look you're gonna come back a year later five months later two months later and go what in the world was i doing what did that mean you get skilled up and you're passing this on to somebody else you know what

[56:47] that variable means somebody else is not going to that's very clear if i were to have that as x as x nobody knows what does x do

[57:02] here make sure you're making notes for yourself don't ever delete anything reach out ask questions be part of a group look this is already hard enough don't be on

[57:16] an island don't do this by yourself and always always always make sure you're always always always make sure you're filling up your toolbox with new skills filling up your toolbox with new skills new problems

[57:29] after you've solved a problem you're like i'm so big and bad i've done this look this is garbage okay get it to work get some success under your belt i used to love hearing

[57:44] well you need to go get some confidence how do you go get confidence you go get successes i want you to go get successes i want you to go learn how to do a problem solve the problem go back

[57:57] do it a month later solve it again you know what you're going to write better i remember if you guys haven't seen the ones that i showed you about prime numbers go go look at the live stream that i did on free code camp i showed

[58:10] first one that i did was disgusting but it worked but it was what the skills that i had at the time i used what i had at the time

[58:23] then i got more skills then i filled up my toolbox and i went from there so all right that's my little rant for but two weeks i don't think i'll be able to

[58:36] two weeks i don't think i'll be able to be back in town for next tuesday uh does want to i don't want to set it up and cancel it because we might be going to that but

[58:49] you're going and checking out my channel down below seeing if there's anything there that i can help you with uh join our discord buy some free code camp merch make sure you're helping them out make sure you're subscribed

[59:05] love the opportunity to be able to do this it really truly is is an honor so i appreciate beau and they are doing some phenomenal work all right guys i'm heading out today

[59:19] uh thanks as always make sure you're liking subscribing sharing um and helping out somebody look if you want to get to be a better programmer go go show somebody something you've learned

[59:34] it'll cement your understanding sorry guys thank you as always and uh i will guys thank you as always and uh i will see you in two weeks bye everybody

More from freeCodeCamp.org

View all

⚡ Saved you 0h 59m reading this? Transcribe any YouTube video for free — no signup needed.