In your code, when you use map(f.addGoodFood, ['SPAM', 'Eggs', 'Bacon', 'Rat', 'Spring Surprise']), the map() function is applying the f.addGoodFood() method to each element in the list ['SPAM', 'Eggs', 'Bacon', 'Rat', 'Spring Surprise'].
The reason you see [None, None, None, None, None] as the result is because the addGoodFood() method does not have a return statement. Therefore, when map() applies the method to each element, it executes the method but returns None by default since there is no explicit return value.
However, when you check f.goodFood after using map(), you can see that the addGoodFood() method has indeed added the elements to the goodFood list. This is because even though the return value from map() is [None, None, None, None, None], the method addGoodFood() is executed side-effectively, meaning it modifies the goodFood list within the FoodExpert instance.
To demonstrate this more explicitly, you can use a for loop instead of map() to see the modifications:
food_list = ['SPAM', 'Eggs', 'Bacon', 'Rat', 'Spring Surprise']
f = FoodExpert()
f.init()
for food in food_list:
f.addGoodFood(food)
print(f.goodFood)
This will output:
['SPAM', 'Eggs', 'Bacon', 'Rat', 'Spring Surprise']
Here, each element from food_list is individually passed to addGoodFood() in the loop, resulting in the elements being added to f.goodFood without the intermediate [None, None, None, None, None] list.