Extend the Lists in One Line
00:00
Instead of adding two lines where you extend the cookies list, you actually can create the cookies list by calling the .on_the_shelf()
function and the .under_the_sofa()
function and add them together in one line.
00:14 I remove the part here, so I adjust the code that it actually just says `cookies = on_the_shelf() + under_the_sofa()`. And when you save and run the code, then you can see that the output is exactly the same list, but you did the whole task in one line instead of adding two lines to it.
00:39
Either way, the two important parts to this exercise are that you must not forget to add a return statement to the .on_the_shelf()
function and .under_the_sofa()
function, because if you don’t have a return statement in a function, then the function always returns None
.
00:55
But in this case, you want to return the cookies so that’s why you need to have return shelf_cookies
and return sofa_cookies
in both functions.
01:04 And then you call the functions and do something with the return value of those functions, which are a list for each. And here you are adding them together into the cookies list, and then you can print it and you get a delicious output.
Become a Member to join the conversation.