Solution: Task V to Task VIII
The solution to the previously assigned challenges: Task V to Task VIII.
We'll cover the following...
Task 5: Students loving McDonald’s fries 🍟
You were to write an anonymous function that returns the number of students from the grouped data who associate the word fries with McDonald’s fries. It can be done by using the lambda keyword and the count decorator together. Look at the snippet:
It’s evident to get the stats; you only need the grouped data (my_data) that was created in the first task. From the grouped data, we start picking the tuples for which fries == 1 is true and store them in a list. Then, we call count on this function, and it will return the number of students that love McDonald’s fries.
Task 6: Students maintaining academics and jobs 👩🎓👨🎓💵
You were to return the students who have secured higher than 3 GPA and earn more than $70,000 anonymously. It can be done using the lambda keyword. Look at the code below.
It’s evident to get the stats; you only need the grouped data (my_data) that was created in the first task. From the grouped data, we start picking the tuples for which GPA == 3 is true, and income is either equal to 5 or 6, and then we store them in a list which is the final answer.
Task 7: Collect weight stats ⚖️
You were to return the number of:
- Females with the
xmost common weight(s) present in the grouped data. - Males with the
xleast common weight(s) present in the grouped data.
It’s evident that to get the stats; you only need the grouped data (data) that was created in the first task and the parameter x setting the limit for the desired common weights. ...