Given a conveyor belt (list) full of assorted Fruit instances (all Apple or Orange),
your job is to sort them into 3 bins (lists): apples, oranges, and rejected.
Test size ('S', 'M', 'L') and quality according to the given attributes;
Reject all fruit that is small (S), medium (M) if less than 90 percent quality
or large (L) if less than 75 percent quality
Return a tuple of lists in apples, oranges, rejected order
:param assorted_fruits: list of fruits
:return: tuple of three lists -- apples, oranges, rejected
我知道如何根据单个特征将它们排序到列表中,比如代码中看到的水果种类,但我不确定如何使用多个特征。任何帮助都将不胜感激
apples = []
oranges = []
rejected = []
apples = [item for item in assorted_fruits if isinstance(item, Apple)]
oranges = [item for item in assorted_fruits if isinstance(item, Orange)]
rejected = [item for item in assorted_fruits if isinstance(item, Rejected)]
相关问题 更多 >
编程相关推荐