Coding 101 12 (Transcript)
Shannon Morse: Today on Coding 101 we check out your viewer submissions and move on with lists.
Netcasts you love, from people you trust. This is Twit!
Bandwidth for Coding 101 is provided by Cachefly. At C-A-C-H-E-F-L-Y dot com.
Fr. Robert Ballecer: This episode of Coding 101 is brought to you by Squarespace, the all-in-one platform that makes it fast and easy to create your own professional website or online portfolio. For a free two week trial and ten percent off, go to squarespace.com and use the offer code CODING.
Fr. Robert: That was different. Welcome to Coding 101, it’s the Twit show where we introduce you to the wonderful world of the code monkey. I'm Father Robert Ballecer.
Shannon: And I am Shannon Morse and for the next thirty minutes we are going to get you all coded up on everything you need to know to be a Python code warrior.
Fr. Robert: A Python code warrior.
Shannon: A Cython Pode warrior.
Fr. Robert: That’s a Cython – no, don’t say that five times fast. That’s right and we’re going to show you some of the more basic parts of the computing programming language known as Python. This comes straight from you, from our chat room and from out Google Plus community. People have said that they’d like us to move a little bit more slowly especially on the basic parts so we’re going to show you one of the most basic data structures you got in Python and explain why it’s important. But before we get there, you’ve got a hard job. You’ve got some great works ahead.
Shannon: Yes we did, we got quite a few interesting viewer submissions. But first I wanted to go ahead and recap really quick downloading Python for your own computer if you haven’t done that already. It’s very simple to do, you just go over to Python.org, download the Python 2.7.6 version MSI installer plus the packages, very easy, it’s just right underneath the download link, and then let’s go ahead and open some scripts shall we.
Fr. Robert: Right.
Shannon: So I wanted to use my example for you. I just wrote this in notepad. It was very simple to do and then I just saved it as a .py so I just clicked file save .py and when I open the script it looks like this, Python.exe. So it says what’s your favorite number. What’s your favorite number padre?
Fr. Robert: Twelve.
Shannon: Twelve okay. What’s your least favorite number?
Fr. Robert: One.
Fr. Robert: So lonely.
Shannon: Your favorite number minus your least favorite number would be eleven.
Fr. Robert: There we go, thank you.
Shannon: Now what’s your screen name?
Fr. Robert: PadreSJ.
Shannon: PadreSJ, so I type that in and hit enter and it says “Thanks PadreSJ your screen name rocks. Press enter to exit.”
Fr. Robert: And that’s it.
Shannon: Very, very simple very easy to write and if I right click on here and I go to edit with IDLE, you can actually see how I wrote the code. So this is exactly what we showed you last week. I ran into one little error right here when I was typing this out. I had to include name space plus space and then quotes, the exclamation mark, your screen name rocks to make it run correctly. The first time I ran it, it just automatically closed because there was a bug, I didn’t include that plus so apparently that is important. So make sure you have that in there if you want to do the same kind of script and then you just click save and save as and I named it Shannonexample12 and down here you'll see it’s called a Python file so Python .py.
Fr. Robert: PY, yeah the extension’s a little bit – actually, you know what, let’s use this to go over some of the very basic stuff and actually Jason if you can go back to her screen we could review some of the lessons from the very first episode so that you can sort of re-catch up with everything we did with Python last week. The first thing you're going to see in her code, as Jason zooms in here, is print. Print is really that simple, it is just print and in quotations you put what you want to print. You could also print just, as you see below the third print statement, you could put print thanks and then a comma which concatenates with name, which is a variable. So printing a phrase, printing a string, or printing a value, it pretty much all works the same. The other thing we want to point out here is the declaration of variables. Remember in C# we had to go through that whole rigmarole of saying it’s going to be an int, it’s going to be a float, it’s going to be a string. Here, we just say the name, the name of my variable’s going to be first thing and that variable will be filled with raw input, which is the Python command to say take something from the use, take something from the keyboard.
Shannon: Yes, there we go.
Fr. Robert: And then in the parentheses, you notice how she has a string inside a quotations, what that function raw input lets you do is it lets you print that out and then wait for the use to respond. Again, it’s not that complicated and she does it several times which shows you that you’re going to use the same techniques over and over but Shannon, way to go. Way to encapsulate everything from lesson one.
Shannon: Yeah, very simple to use and I just wanted to take everything we learned and just stick it in to one code. It was – yeah, it was nice and easy so I really enjoyed doing that one. I also had a couple of viewer submissions to show you this week. The first one comes from Benjamin Frost and this is over on our Google Plus community if you want to join that. I went ahead and copied and pasted his code and created my own little notepad file. If I open this it says “Asking program by Ben”, “When you have answered a question, press enter to continue”, “What is your first name?” So I’ll just put Shan, last name Morse. “When were you born?” 19, let’s say 84, not really but that’s okay.
Fr. Robert: There we go.
Shannon: “Where do you live?” Cali, and “How many kids do you have?”
Fr. Robert: Ten.
Shannon: I’ll put ten, okay ten.
Fr. Robert: Thank you.
Shannon: So you are between 29 and 30 years old that’s true if I was born in 1984. You live in Cali and have ten kids, which means you are possibly going to have ten to twenty grand kids. Now, so he did some math here, and I'm’ going to show you what that looks like when I click edit with idle. So when I open this, you’ll see down here, so he chooses the grand kids, he’s basically choosing to say “Hey, if each of your kids had two more kids themselves, multiply that by two so you’d end up with ten to twenty grand kids.
Fr. Robert: There we go, yeah.
Shannon: That’s it, very simple to use and it has multiplication in there.
Fr. Robert: So it’s very simple math but – yeah we love it, you take in some information from the user and you give something back out, that’s essentially what programming does.
Shannon: The second one I wanted to show you was from Santi Esco, also in the Google Plus community. Now if I click on this one, I'm going to show you how I was able to open this on my computer. So I copy and paste this, and then I'm going to open notepad and then I’ll just scoot this over for you. So I paste the code into here and then I click print, save as or file save as excuse me. And I'm going to save that over at my desktop where all my other files are under Python.
Fr. Robert: In Python.
Shannon: Yeah, I made a pretty little Python folder. So I'm going to call this Santi.py. Now when I open it, let’s click on that. Okay, “Welcome, Please enter your name” Shan, “Enter your last name” Morse, “Enter your age” 12.
Fr. Robert: Why do they all want to know your age?
Shannon: So that one automatically closed. Did you notice that?
Fr. Robert: Ah yes, yes.
Shannon: Because I'm on Windows.
Fr. Robert: That’s right, you're on Windows, you're on the shell. Which is why we always put that raw input at the end—
Shannon: That’s right.
Fr. Robert: …to say hit the enter key to continue.
Shannon: So I'm just going to copy that from my code right here, raw input, copy and I’ll just stick that into his code.
Fr. Robert: Remember folks this is one of the things that we learned with Dale, which is if you're using windows the terminal window won’t stay open once the program is done, so what we do is we kind of cheat. We put another input in there that waits until you hit enter to clear the screen.
Shannon: There we go.
Fr. Robert: There we go.
Shannon: So this one had just a quick input and output. Shannon, last name is Morse, your age is twelve.
Fr. Robert: Fantastic.
Fr. Robert: Now one of the things we love about this is you saw how easy it is to write programs in Python. You don’t have to turn it into a binary, you don’t have to turn it into an exe.
Fr. Robert: If you’ve got the code, so in her case you wrote in a notepad. In the case of our fans in the Google Plus page, they just gave us a link to their program. You can just copy and paste it in to the IDLE shell and it will run it for you. We’ll compile it and you're good to go. That’s one of the powers of and interpreted language.
Shannon: And we should mention in our show notes of course we always have the github link as well so you can download all of the code that is shown in the show so that you can play with it in your computer. It’s very easy to download from github, I was able to download all of our Python code so far by just hitting the zip file, that’s it.
Fr. Robert: Right, and the other thing to remember is folks we always put all the code from our show into that github so if there’s something that you're a little curious about as the show runs on, don’t worry about it, don’t freak out, you can always go to the show page it’ll be right there, you’ll get an exact copy. You don’t have to copy anything off the screen, all we’re trying to show you are the basic principles that make it work.
Shannon: Yes, let’s move on.
Fr. Robert: Well I’d love to move on but before we do that, you want to take a little bit of a break. Why don’t we talk about one of our sponsors.
Shannon: Ooh, which one is it.
Fr. Robert: A brand spanking new sponsor.
Shannon: Yes, we did.
Fr. Robert: Because without variable you can’t really—
Shannon: You have nothing.
Fr. Robert: You have nothing right? You can hard code a program to do something but you need something to maintain temporary data or pull data in from users, that’s why we have variables.
Fr. Robert: But did you know there's something even more useful than a variable?
Shannon: Hmm how can something be more useful than a variable?
Fr. Robert: Well imagine this, imagine if you didn’t just have a loose collection of variables, var1, var2, var3, var4 whatever it’s going to be. But you can start grouping together similar data.
Fr. Robert: For example, let’s say I wanted to get the first name of everyone in the studio, I could say name 1 equal name 2 equals name 3.
Shannon: That would take a long time now, people don’t want to do that.
Fr. Robert: It takes a long time, yeah exactly. And it’s not that useful because all you do is you end up with a jumble of variables that could be a name, it could be the name of a product, it could be just lunch whatever it’s going to be. Inside of Python, and in fact inside of all programming language, there’s a thing called structured data. And when we get structured data and data structures, it allows us to group together similar variables or variables that we think should be related to one another and create a list.
Shannon: Ah, hence lists.
Fr. Robert: Hence lists, right. But does that make sense, does that make sense why you’d want to group them together?
Shannon: Yeah it totally makes sense. I wouldn’t want to spend the time to name a different variable for each and everything that I enter.
Fr. Robert: Right.
Shannon: It would just kind of be annoying if they’re all comparable to each other.
Fr. Robert: Yeah, now inside of a list we do just have variables. They are just variables but they are strung together in a sequence. And we’re going to show you exactly how you access that sequence, how you initialize it, how you fill it with values and then how you change and output those values. That’s the part of the lesson that we’re going to try to bring you here in episode two. Now the first thing we want to do is we want to show you the syntax of a list, of a sequence.
Fr. Robert: Now, if you go ahead and go over to my computer Jason, this is what it looks like when you want to create – oh if this’ll work, if you want to create – hold on my computer’s suddenly gone wonky. If you want to go ahead and create a list, the way we’re going to do it is you need to do the name of the list then equals and then in brackets you want value 1, value2, value3, value4 whatever that’s going to be.
Shannon: Oh, okay.
Fr. Robert: So for example, if this was going to be first names, I could say the name of the list is first name and then equal and then I put in quotations Robert comma in quotations Snubs comma in quotations Bryan comma in quotation Leo and I can list the names, the first names of all the people in the Brick House and then I end it with a semicolon.
Shannon: Oh, so we have a semicolon again.
Fr. Robert: There we go, semicolon’s back right? But that just tells me that I'm done with this list. That tells me that I've finished it up. This is the basic structure of any list that you declare in Python.
Fr. Robert: Does that make sense?
Shannon: Yes, so far it does.
Fr. Robert: Is that easy to understand? Right, and the reason why we want to do that is because we want what’s called the index.
Fr. Robert: So if you think about that bracket, once I have those values inside that data structure, if I use the name of my list, so let’s say it’s first name and then I put the bracket and then I put a number—
Shannon: In the middle of your bracket?
Fr. Robert: In the middle of the Bracket, what I'm doing is I'm actually calling forth the value of a particular element inside that data structure.
Fr. Robert: Right, starting from zero, so the very first one is zero because remember in programming we start at zero.
Fr. Robert: So go back to that previous example, the first one is Robert and the second one is Snubs.
Shannon: That would be zero, that would be one.
Fr. Robert: And the third one is Mark, that would be two. And the fourth one is Leo, that would be three right?
Fr. Robert: So I wanted to call that, I would just put the name of the list and then in brackets, three.
Shannon: Oh, that’s easy.
Fr. Robert: Right.
Fr. Robert: Okay so that’s how I address it. Now let me actually show you what that looks like when you start using it.
Fr. Robert: Now we want to access these contained within the list so the first thing we’re going to do is we’re going to fill the list with values that we actually want to use. I've got some pre-coded examples here, let me go ahead and get rid of this stuff. And we going to do this, so we’re creating a list called C101, Coding 101 and it’s equal to PadreSJ, Snubs, Dale Chase, Cranky_Hippo.
Fr. Robert: So when I hit enter, that line has already been entered in right? So I have just created a list called C101 with those four entries, those four values, right?
Shannon: Got it.
Fr. Robert: Okay now, quick question, if I wanted to print one of those, let’s say I printed position one, what would it print?
Shannon: It would print Snubs.
Fr. Robert: Exactly right?
Shannon: Because that was one.
Fr. Robert: That’s a one, which is actually the second position. Just a quick test because some people get kind of messed up with that. Remember whenever we’re dealing with these, we always start at zero. All right, now we created the list but now we want to actually do something with it. So what I want to do is I want to say go ahead and print everything that’s in the list. I'm going to do it the easy way, sort of the broke way, which is this, I'm just going to say print “The following are members of the Coding 101 team:”, and then see what I'm doing, print C101 index 1—
Fr. Robert: …or index zero—
Shannon: Okay so you have the brackets and then the variable number or whichever one—
Fr. Robert: Exactly the index number.
Shannon: Index number.
Fr. Robert: So when I hit enter, it just does that.
Shannon: That’s cool.
Fr. Robert: So it dumped the index back out to the screen.
Shannon: You should probably put some commas in between those.
Fr. Robert: Yeah, yeah exactly we weren’t too worried about that I just – I wanted to do a dump of all the names that were inside the list back out to the screen.
Fr. Robert: But you could see where this could become handy, right?
Shannon: Yes, definitely.
Fr. Robert: Do you remember something from C# that we maybe could use to fill up that list rather than hard coding it?
Shannon: Ooh, oh are you saying—
Fr. Robert: The looping.
Shannon: …the loops? Yeah.
Fr. Robert: Yeah so if we wanted to, we could say use the – we could, remember how there’s a counter, an increment or decrement counter.
Fr. Robert: We could start it at zero and then say something for every time this loop runs, take the next data point and put it in the index of that increment number.
Shannon: Oh, you're totally integrating lists into loops, I love it.
Fr. Robert: There we go, now we’re not going to do that yet. We don’t want to blow your mind.
Shannon: But I'm ready, I want to do it.
Fr. Robert: No, no, no, no, no we’re not going to sneak ahead but just know that we could do that. And that’s the power of the list that I want you to see. As we head further into Python, that’s probably one of the things that you will end up doing.
Shannon: Oh that’s fun, I love it.
Fr. Robert: Okay, now it’s just a matter of filling up a list and then dumping it out to the screen. If we did that, that would be kind of silly. That’s actually no all that useful. What we can do is we can change what’s going on inside the list itself. This is one of the things that we need to learn because it’s actually important. So if I wanted to update let’s say value number 3, so value number 3 is what? Or let’s say I want to change value number 4, which is Cranky_Hippo right?
Fr. Robert: I'm going to say “Wait a minute, that’s not Bryan’s real name. He’s not actually called Cranky_Hippo, his real name is Bryan Burnett.” So what I'm going to do, if I can find my cursor, is I'm going to do this. C101 index 3, which is the last entry, that’s the fourth one is equal to Bryan Burnett.
Shannon: Bryan Burnett, so all you have to do is type in the name of your list plus the index number, wherever his name falls equals and then in quotations whatever you want to change it to.
Fr. Robert: Right, exactly so here we go. Now that I've updated that, if I put back the last piece of code, which just printed everything that was in the list which again was print and then in quotations the following are members of the Coding 101 team, I get something that looks like this. And that last entry has changed to Bryan Burnett.
Shannon: Oh that’s cool, that’s so easy.
Fr. Robert: Now this is messy, this is kind of screwy.
Shannon: That’s okay.
Fr. Robert: It’s okay because what we want you to see is we want you to see how easy it is to work with lists.
Fr. Robert: Again lists are a fundamental part of programming, you need to have data structures in order to go beyond just simple hello worlds. What we want to do is give you this little bit of theoretical understanding so that as we move on and we do things like, oh I don’t know, Google Doc integration you'll be able to import data from an external source into a data structure that keeps everything nice and neat.
Shannon: Ooh, that’s going to be fun.
Fr. Robert: Does all this make sense or am I going way too fast.
Shannon: It makes sense to me but of course if you guys ever have questions we’ll be happy to share them on the show and you can share those with us. What’s our email address?
Fr. Robert: Well we don’t use email.
Shannon: I don’t think we have an email.
Fr. Robert: We don’t use an email address. What we use is we use our Google Plus community right?
Shannon: Yes we do, it’s gplus.to/twitcoding101.
Fr. Robert: And also our twitter addresses which we’ll give you at the end, so I you want ask us a question, wait around till the end. Now Shannon, I feel like we’re missing something.
Shannon: We are, I feel kind of lonely in here.
Fr. Robert: Yeah it’s just the two of us, I mean normally we’ve got like a code warrior or something right?
Shannon: What’s going on? I think we do. Do we have Dale?
Fr. Robert: Yeah Jason, do we have someone we could bring in who maybe could shine – oh, whoa this is new.
Shannon: Hello Dale. Oh look he’s flying in.
Fr. Robert: Okay, he’s one with the force.
Dale chase: [makes noises]
Fr. Robert: Dale Chase with Discovery Networks, how – sorry, Discovery Digital Networks how are you today?
Dale: I'm great, great to see you guys.
Fr. Robert: Great to have you back. I see that you’ve got a nice – you're helping us with the nice USB headset so we get a little bit more Daleness in our ears.
Dale: Yeah you can hear the bass of my voice now.
Shannon: Oh yeah.
Fr. Robert: There we go. Wow, suddenly I don’t really want to program anymore. No, no, no – whoa that was way too much. Okay Dale so – thank you. So we are talking about lists. We’re specifically talking about how to get data into and out of lists and then maybe doing a few things with comparing the actual elements within a list. What do you got?
Dale: Well, I don’t actually have anything comparing the elements, which I can probably throw together really quick though. What I've got is a list that I put together of a few Doctor Who companions.
Fr. Robert: Oh okay.
Dale: And essentially just prints, it calls the third position which is Rose Tyler and prints that out in a statement.
Shannon: Oh that’s cool.
Dale: So I can just let that go off for you really quickly.
Dale: So the doctor once traveled with Rose Tyler, who is as you can see companions 2 in my print statement on line 5 here.
Fr. Robert: Right, right.
Shannon: And then at the end you put a plus and—
Dale: A period.
Shannon: A period.
Fr. Robert: Now we got to ask you Dale, so this – what you gave us is exactly what I asked for, which is something crazy basic. So this exact example is going to go on our show notes so that people can play with lists. What you’ve done here, the very first line, is going to create a list called companions and then it’s going to fill it with a values of Sarah Jane Smith in position 1, Leela in position 2, Rose Tyler in position 3. So that’s zero, one and two. Then that second line is going to print first the string The doctor once traveled with, comma which is going to concatenate it with the value of list called companions index 2 which is actually position 3 plus a period. And then you're going to – you do raw input because again you want the window to stay open.
Dale: Right, now I do have an alternate version which uses actually a basic loop – a basic Python loop that’ll print out every entry in the list. You want to see that?
Fr. Robert: Well let’s see that, I want to see it, yeah.
Dale: So I will just—
Shannon: Do it.
Fr. Robert: Do it.
Shannon: Oh so you put it down there, comment it out.
Fr. Robert: He just commented it out. He’s smart.
Fr. Robert: I know.
Shannon: Dale is smart, that’s why he’s our—
Fr. Robert: I would do that if I was as smart as Dale.
Shannon: …that’s why he’s our code warrior.
Dale: [laughs] so what I've got here is – so there are a few different ways to do loops in Python but this is a very simple way to go through a list. If you're not really concerned with doing numerically, if you just want the contents, you could do four and you just create a new value here essentially which is going to become what you work with. So I've got four companion in companions, which is you know the variable here. And then I just iterate through each one in the print statement and so I call companion and then concatenate the rest there. So let’s see what that looks like. I’ll just clear this and now we have three statements.
Shannon: Oh that’s cool.
Fr. Robert: There we go. So what you told it to do is you said “Okay take this list and go through all the elements in the list and go ahead and print the bottom screen”.
Fr. Robert: Now we could theoretically, we could use this same sort of programming to fill the list right? We don’t have to hard code the list into the actual program.
Dale: That’s correct. You wouldn’t use this sort of loop.
Fr. Robert: Right, right, right.
Dale: But you could essentially—
Fr. Robert: Yeah the problem with using – you couldn’t use this kind of loop because this loop actually depends on a list that has already been preset to determine how many times it’s going to run. You would actually need some way to tell the loop how many times it’s actually going to go before it stops.
Shannon: Oh yeah that’s a good point, so it doesn’t just keep on going and going.
Fr. Robert: Right, right. So you could use like for example a Whileloop.
Fr. Robert: You could have a user character at the end that says “Do you want to continue? Yes or No” and if you say yes it does another iteration of the loop, if you say no it going to go ahead and end the loop and you’ve got your list.
Shannon: Ooh, I could totally start doing my games again.
Fr. Robert: Yeah, yeah.
Shannon: Yay, text adventure games.
Fr. Robert: Now Dale we’ve got to ask this because this is actually coming around in the chat room, people are saying “Oh this looks a lot like arrays” and this essentially – this is what python does for arrays. This is a basic data structure that allows you to create an array of information.
Dale: Yeah and this is Python’s native array essentially.
Fr. Robert: Yeah, yeah and just like an array we could actually have lists of lists, we could embed lists within lists—
Shannon: Oh really.
Fr. Robert: …if we wanted to make multidimensional lists.
Shannon: So why would you want to do that?
Fr. Robert: Well sometimes people like more complicated data structures so they have better ways to store things.
Shannon: Oh okay.
Fr. Robert: Sometimes people want to be able to refer to things by coordinate system. What I prefer is I actually like to keep my lists nice and simple so I probably wouldn’t do that. But Dale do you have much call for doing lists within lists?
Dale: Yeah, actually and array or arrays often. If let’s say we’ll look ahead to looking at a Google Spreadsheet, if I call a row in a spreadsheet that I get back an array.
Fr. Robert: Right, right.
Dale: But as I go through each row of the spreadsheet I'm creating an array of each of these rows which is exactly that.
Fr. Robert: Which is a nice way of saying “We could take all the information out of a spreadsheet and we could organize it by saying this is a list and this is a list and this is a list and this is a list”.
Shannon: Oh that’s cool.
Fr. Robert: And so now we have everything organized by according, either through their rows or their columns depending on how you wanted to do it and you have lists within the larger lists.
Shannon: That’s really awesome.
Fr. Robert: Yeah, it’s actually, it’s what we do a lot. Yeah, so Dale let me ask you this, as you're looking through this lesson, as you're looking through lists, what else do you think people need to know before they take you're lessons and go forth and list up?
Dale: Well if they're looking to try looping on their own to create the list, what they’ll want to do is something like this if you want to just look at back my screen really quickly, is just do something like newlists equals – oh wait no it’s newlist I believe it’s something like this.
Fr. Robert: Right, right there it is.
Dale: Value, so to kind of create without knowing what the index is – add that value to the list, you want to put the brackets in front of the variable name and that will just automatically create the index for you as you continue to just add values.
Fr. Robert: Right, right.
Fr. Robert: And again the reason why we’re doing this is because when we’re dealing with Python and variables in Python, variables in Python are dynamically created, they're dynamically initialized, dynamically declared. So unlike C# where we would have to declare the array, at start of the program here, we could actually have it continue to add as we add values.
Shannon: That’s cool.
Fr. Robert: Yeah, Dale this was the only example you showed me the other night. You were starting to get kind of crazy towards the end. When you think of the ways you use lists, is there an example you could give us that won’t blow our young users’ minds just yet.
Dale: Just yet, okay well maybe we want to add or remove things from the lists?
Fr. Robert: There we go, that’s what we’re looking for.
Dale: All right, okay well something that is very useful, I don’t think this should be too mindblowing but it’s definitely—
Fr. Robert: It’s useful.
Dale: That’s useful, I'm going to go with pop.
Dale: Can I go with pop?
Fr. Robert: Yeah go ahead, do pop. Let’s – you know what yeah, pop. We’re doing pop, add pop.
Dale: Okay, so this is not adding anything, this will remove and item from the list while allowing you to use that item as it’s deleted from the list.
Fr. Robert: Which—
Shannon: That’s confusing.
Fr. Robert: No, no, no this is perfect imagine this, imagine you were doing a sort right?
Fr. Robert: So you wanted to resort everything—
Fr. Robert: …according to let’s say we want to do by first name.
Fr. Robert: What you’d want is you’d want some sort of algorithm that would sort from the list to a new list that’s actually sorted.
Fr. Robert: But you want a way to make sure that you don’t double enter, right?
Fr. Robert: So you could do this, you would pop it. In other words you would use it as you move it but then it would remove it from the old list so that you won’t have to worry about sorting it multiple times.
Shannon: Oh okay, okay I get that. We can do that.
Fr. Robert: Show us some pop dale.
Dale: So what I'm going to do is I'm going to use my initial statement and now – actually you know what, let’s use this in conjunction with the for loop.
Fr. Robert: Yeah, yeah that sounds good.
Dale: So what we’ll do here is now it’ll loop through and with each iteration will – let’s see what’s the best way to show this off. Oh yeah since I'm only grabbing zero, that’ll become – so each time we go through, what’s left in the list will become zero.
Fr. Robert: Correct.
Dale: And you’ll see the same kind of statement that we have before but now I'm only using one - and that should work – actually no, it that going to work?
Shannon: Do you have to change companions to companion?
Dale: Actually wait.
Fr. Robert: No because—
Dale: Actually that should work actually, that will work.
Fr. Robert: Let’s run it and see.
Shannon: It did.
Fr. Robert: There we go.
Dale: So it did Sarah Jane and Leela and so it didn’t do the last one. It got a little of a off by one error here I guess. It didn’t get to rows.
Fr. Robert: While you troubleshoot that, what’s happening is as this is going through the list, so as that loop is going through the data in the list, as it prints it out the screen, it’s removing it from the list.
Shannon: Got it.
Fr. Robert: Okay, and this folks—
Shannon: So it’s basically pushing the next one up to the front of the list.
Fr. Robert: Yeah and folks what this is ,is this is data management. This is again one of those basic things that you're going to have to do whenever you're writing a program especially a program that starts to grow beyond just a single page or a single set of lines. You're going to have to figure out a way to manage your variables and manage your data flow so that it doesn’t become this crazy, ridiculous, overwhelming hydra of lists and variables. Pop is used all the time, whenever we want to make sure that we’re properly managing the data in a program.
Shannon: Now can you use other types of pops I guess would be my question?
Fr. Robert: The like m pop?
Shannon: Like can you add things instead of just removing them.
Fr. Robert: Yes you can.
Dale: We probably shouldn’t have started there.
Fr. Robert: No, I liked the pop but go ahead and go to the ad.
Dale: But before we do that I just wanted to point out really quickly we haven’t – this is our first time getting to this, and the way that Python pays attention to spacing.
Fr. Robert: Yeah.
Fr. Robert: We talked very briefly about whitespace but now we start getting into the special cases.
Dale: Right because here, we have a situation here where we’ve got a for loop here in the past in C#--
Fr. Robert: And then you have an index.
Dale: …this would be surrounded by—
Fr. Robert: Brackets.
Dale: Brackets, right which we don’t have here. Python is paying attention to the colon here and the fact that we have this line indented a couple of spaces.
Fr. Robert: Right.
Dale: So that’s how we indicate to Python how this is now a block of code separate from the rest.
Fr. Robert: In C#, as long as it’s within those brackets it knows that it’s a part of that loop.
Fr. Robert: In Python, as long as it’s indented it knows that it’s a part of that loop.
Shannon: Oh that’s crazy.
Fr. Robert: Yeah, which actually, we like this because it’s much easier to understand right? I mean as long as it’s indented you know that it belongs to the thing, that’s not.
Shannon: So do I have to that whenever I'm doing code in notepad as well?
Fr. Robert: Yeah, so if – yeah, if you don’t indent and then you bring it into IDLE, it won’t know where the loop starts and stops.
Shannon: Oh okay.
Fr. Robert: Okay, Dale continue, sorry.
Dale: Yeah sometimes I just pop this append line in here after the declaration and just print out what we have now. So I'm doing companions and then so the built in function for list to add one item is append, which is .append. And so I’m just going to add Martha Jones and see what that does.
Fr. Robert: There we go.
Shannon: Hey, it worked.
Fr. Robert: And it’s back, it adds its name to the list.
Shannon: That’s cool.
Fr. Robert: Now these simple, simple things so popping and appending are the way that you could dynamically change your list as the program goes on.
Fr. Robert: Okay, now Dale if we wanted to give our folks some homework, I think we should probably include some popping and appending right?
Fr. Robert: What would you say, as a code warrior it is your call. What do you want them to do? What do you want them to submit to our Google Plus group?
Dale: Let’s see.
Fr. Robert: Be mean as you want, it’s cool. Let it out, let it out.
Dale: Well I want them to make my first example of popping work correctly.
Fr. Robert: Okay, actually now that’s perfect, okay.
Shannon: That’s a good idea.
Fr. Robert: Yeah so recreate Dale’s list which we are going to have in our code example and figure out why it only popped two of the entries. So submit the code and actually it was already answered in the chat room so don’t look at the chat room. Don’t look at the chat room. Don’t look at the chat room. Submit it into our Google Plus page and we will feature you on the next show.
Shannon: Oh okay, I get it.
Fr. Robert: Don’t look down there.
Shannon: Okay I won’t say it. I’ll wait until the next episode.
Fr. Robert: They’re cheating, they're cheating. Oh great, now everyone’s thinking.
Shannon: I want to share some more viewer submissions as well. We’re going to do my own too so that you guys could see what I came up with. It won’t be a Doctor Who reference for mine, maybe I’ll do a Star Trek one.
Fr. Robert: Yeah, yeah Dale let me ask you this. So what do we have on tap for the good folks next week? This was great, we had to bring them into a data structure but now that they’ve got that data structure, where do you want to take them?
Dale: I’m not sure exactly. Where do you think we might want to go?
Fr. Robert: Be mean man, be mean. Come on let’s do it. I’ll take my lead off of you.
Shannon: No one leave me back behind.
Fr. Robert: No we won’t leave you back behind—
Shannon: You better not.
Fr. Robert: But you know what, I think looking at the chat room, we’re going to have to give them loops. Why don’t we give them every kind of loop and we’ll give them every kind of example.
Dale: Yes, yes..
Fr. Robert: Sound good?
Dale: Yes, yes. We’re going to have a lot more fun now, yeah totally.
Shannon: Oh yay.
Fr. Robert: Dale Chase from Discovery Digital Networks, thank you so very much for being our code warrior again, it’s great to have you and we will see you next week.
Dale: Catch you guys later. Thank you, bye.
Fr. Robert: Folks that’s about it for this episode. I think—
Shannon: Yeah it was a great one.
Fr. Robert: Not too much data that you can’t sort through it but some really good things that you need to now go out and practice. And the way that you're going to practice that is that you’re going to go to our show notes page. We don’t want to leave you hanging. We know that there were some people who were complaining that you couldn’t see our screens. Well we’re going to give you all the code that you saw during the episode. All you need to do is go to our show notes page at twit.tv/coding101. There you’ll be able to find all of our episodes plus if you click the episodes, you'll see where we have a link to our Github. We’re going to give you each and every exercise file so that you can copy it over to your IDLE and be happy.
Shannon: Guess what else.
Fr. Robert: What?
Shannon: We’re still on Itunes.
Fr. Robert: Yeah we are, that’s right.
Shannon: Yeah but I don’t know why they haven’t kicked us off yet but they haven’t.
Fr. Robert: They haven’t caught on.
Shannon: Yeah so search us on Itunes we’re under Video, I think we’re on audio too I maybe.
Fr. Robert: Yeah, yeah video, we got high definition video, medium definition video, and audio so you can always download the version that you want. And please, please make sure you subscribe and tell your friends about us because we were doing really well in the Itunes store for a while, we want to get back up there you know. Coding101, coding is generally something that we should all know about. Speaking of something that we should all know about, we should all know about our Google Plus community. If you're not a member of our Google Plus community, why the heck aren’t you? Shannon where can they find us?
Shannon: That’s over at Gplus.to/twitcoding101. Nice and easy to know and we have so many good examples in there from everyone. Sorry we couldn’t get to all of them today, I guess we could’ve had time if we wanted to but there are plenty of great examples in there to get you kind of get your feet in the water as far as it goes with Python.
Fr. Robert: Yeah and the nice thing about Python folks is that if someone gives you the code inside that group, you actually just can copy and paste it. It’s really that simple. Again one of the advantages of—
Shannon: Just like I did.
Fr. Robert: Like Snubs, of an interpreted language. Now Google’s not the only place to find us, you can also find us on twitter where if you follow us you'll be able to find out what we’re going to be doing each and every single week, you’ll find out what we’re doing in future modules. And this is the important part, remember when we went from C# to Python we had those two wild card episodes that were spectacular. We talked to Liam Kennedy then we talked to our very own Randall Schwartz.
Shannon: Randall Schwartz, he was so good.
Fr. Robert: And, you know we show you why you want to learn these things. We show you people who are actually professionals who are in the field, who are doing it now. So follow me at that’s @PadreSJ.
Shannon: And I am @Snubs.
Fr. Robert: Yeah and finally if you watch us live you get to see all the things that we do before and after the show.
Fr. Robert: You can catch us each Thursday at 1:30 Pacific time here at live.twit.tv.
Shannon: And we’re also at the chat room, we've been watching it during the show and we’d like answer questions whenever you guys have them. That’s over at IRC.twit.tv and you can definitely jump in there during the live show.
Fr. Robert: Until next time, I'm Father Robert Ballecer.
Shannon: I'm Shannon Morse.
Fr. Robert: End of line!
Shannon: End of line.