class Trip(object):
'a class that abstracts a trip to a destination'
def __init__(self, destination='Nowhere', items=[] ):
'Initialize the Trip class'
self.destination = destination
self.items = items
class DayTrip(Trip):
'a class that abstracts a trip to a destination on a specific day'
def __init__(self, destination='Nowhere', items=[] , day='1/1/2019' ):
'Initialize the Trip class'
self.destination = destination
self.items = items
self.day = day
class ExtendedTrip(Trip):
'a class that abstracts a trip to a destination on between two dates'
def __init__(self, destination='Nowhere', items=[] , day='1/1/2019' ,
endDay = '12/31/2019' ):
'Initialize the ExtendedTrip class'
self.destination = destination
self.items = items
self.day = day
self.endDay = endDay
def luggage(lst):我想要行李箱把所有的物品从每一个班级,并打印一份清单上打印的所有独特的项目。
以下是一些示例输入:
trip1 = Trip('Basement', ['coat','pants','teddy bear'])
trip2 = DayTrip('Springfield',['floss', 'coat','belt'], '2/1/2018')
trip3 = ExtendedTrip('Mars',['shampoo', 'coat','belt'], '4/1/2058')
trip4 = ExtendedTrip()每次旅行都被附加到一个列表中,然后它将接受一组项目列表,其中打印如下:
{'pants', 'belt', 'toothbrush', 'floss', 'shampoo', 'teddy bear', 'coat'}发布于 2018-01-15 23:44:57
尝试如下(未经测试)的内容。
def luggage(lst):
items = set()
for trip in lst:
for item in trip.items:
items.add(item)
return itemshttps://stackoverflow.com/questions/48271810
复制相似问题