list-based implementation the implementation of the bag adt using list is shown in listing the constructor defines single data fieldwhich is initialized to an empty list this corresponds to the definition of the constructor for the bag adt in which the container is initially created empty sample instance of the bag class created from the example checkdates py program provided earlier is illustrated in figure listing the linearbag py module implements the bag adt container using python list class bag constructs an empty bag def __init__self )self _theitems list(returns the number of items in the bag def __len__self )return lenself _theitems determines if an item is contained in the bag def __contains__selfitem )return item in self _theitems adds new item to the bag def addselfitem )self _theitems appenditem removes and returns an instance of the item from the bag def removeselfitem )assert item in self _theitems"the item must be in the bag ndx self _theitems indexitem return self _theitems popndx returns an iterator for traversing the list of items def __iter__selfitem )most of the implementation details follow the specifics discussed in the previous section there are some additional detailshowever firstthe adt definition of the remove(operation specifies the precondition that the item must exist in the bag in order to be removed thuswe must first assert that condition and verify the existence of the item secondwe need to provide an iteration mechanism that allows us to iterate over the individual items in the bag we delay theitems bag figure sample instance of the bag class implemented using list