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:
from task1 import group_values_with_columnsfrom task2 import count# Students loving McDonald's friesMcdonalds_fries = count(lambda my_data: [entry for entry in my_data if entry.fries == '1'])# Calling the functiongrouped_data = group_values_with_columns(data, required_columns, n=60)print(Mcdonalds_fries(grouped_data))
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.
from task1 import group_values_with_columns# Getting bright studentsbright_students = lambda my_data: [entry for entry in my_data if entry.GPA > '3' and (entry.income =='5' or entry.income == '6')]# Calling the functiongrouped_data = group_values_with_columns(data, required_columns, n=60)students = bright_students(grouped_data)for entry in students:print(entry)
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
x
most common weight(s) present in the grouped data. - Males with the
x
least 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 ...