Extend the Cookies Lists
00:00
One way to add the return cookies to the cookies list, you can add another line after the empty cookies list and add items from a list to another list with the +=
operator.
00:15
So you can write cookies +=
, and then a call to the on_the_shelf()
function first. Don’t forget the parentheses to actually call the function, and it’s for now save and run the code.
00:34
Then you can see that the cookies list now contains Peanut
and Chocolate
.
00:40 So in order to also add the cookies that are under the sofa, you repeat almost what you just wrote. `Cookies += under the_sofa()`.
00:53 Again, don’t forget the parentheses to call the function and now when you save and run the file and then the list contains Peanut, Chocolate, Oat, and Salted Caramel.
01:03 That is one verbose solution to the task. But I also want to show you another solution which is a little bit less verbose. Let’s check this out in the next lesson.
Become a Member to join the conversation.