1
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):

I want luggage to take all of the items from each class and print a list printed of all thew unique items.

these are some example inputs:

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()

Each trip is appended to a list and then it will take a set of the list of items which prints this:

{'pants', 'belt', 'toothbrush', 'floss', 'shampoo', 'teddy bear', 'coat'}
Joey Lesus
  • 19
  • 8
  • 1
    You're going to run afoul of the Mutable Default Argument: https://stackoverflow.com/questions/1132941/least-astonishment-and-the-mutable-default-argument – Patrick Haugh Jan 15 '18 at 23:02

1 Answers1

0

Try something like the following (untested).

def luggage(lst):
    items = set()
    for trip in lst:
        for item in trip.items:
            items.add(item)
    return items
Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52