I am working on the Betty’s Bakery assignment and in question 6 they ask us to find all recipes with one egg and to use a logical statement to get True or False for each value of eggs. However, in the video tutorial it just finds and prints the recipes that contain one egg and doesn’t use any True/False statement. https://www.youtube.com/watch?time_continue=1&v=bv5x0BrFyMU&feature=emb_title
Am I interpreting the question incorrectly or is the video missing something? Maybe as a non native speaker I am missing something?
I tried to get a list with True or False, but was only able to do it for a single row in my list using a lambda function:
Keep in mind that a lambda function is just a function, there’s really no such thing as a lambda function, it’s just a way you can define a function, does nothing special, only affects how you type when writing it.
return eggs == 1
Your data probably contains more than just an egg count, so you’d need to dig the egg count out of it:
But there was the possibility to have 1, 2 or 3 eggs so then it is not a boolean right? Also I tried to see if using strings instead of just a boolean statement was a solution, so I did write the true and false as booleans first.
Would your function print a list that gives a boolean statement where 1 egg is true and any other amount is false? or would you need to add extra lines that write it as a boolean statement.
Sorry, I am still really new to coding and all the terms are not all correctly stored up there.
what does == return?
after that operation, you have a boolean. what do you do after that? you do an extra operation where you test if it’s one thing or another, and regardless of which it is, you return the value that you already had, making this test do absolutely nothing useful
strings do not represent truthfulness, the text true/false has no special meaning. it’s text.
my functions do nothing with lists. look at the operations in them. no list things. not going to happen.
but you can apply a function to the things in a list to get a list of the results
The solution provided by codeacademy indeed filters out the ones that satisfy the “contain one egg” condition, which I understand and it makes sense, but the question seems to ask for a list of booleans for the list of eggs, with the clause being that it contain one egg. I assume it is possible to make that list of true/false statements although it is probably quite unnecessary for most problems?
You can’t put statements in a list. A list can refer to values. True and False are values, so you can put them in a list, but a statement like a for-loop is not something you can put in a list.
If you have a function that accepts a recipe or row whichever you plan to send to the function, then you could map that over all of them which would get you an iterable of results which you could collect into a list. This is what my example above does.
there are some original values there, a function that turns such a value into a result, this function is applied to each original value to obtain a list of results. it’s the same thing as you’re describing
Ah okey, thanks. I haven’t seen the map function explained yet in one of the excercises but I understand the idea of it by what you describe. I will definitely come back to this and see if with more information I can solve this completely by myself when I have learned more.
I have just come to this, and I had the same question - I interpreted the task the same as the original poster and the video walkthrough didn’t seem right. There was an earlier task that used True/False in an array so I knew it was possible.