linked structures listing the llistbag py module implements the bag adt using singly linked list class bag constructs an empty bag def __init__self )self _head none self _size returns the number of items in the bag def __len__self )return self _size determines if an item is contained in the bag def __contains__selftarget )curnode self _head while curnode is not none and curnode item !target curnode curnode next return curnode is not none adds new item to the bag def addselfitem )newnode _baglistnodeitem newnode next self _head self _head newnode self _size + removes an instance of the item from the bag def removeselfitem )prednode none curnode self _head while curnode is not none and curnode item !item prednode curnode curnode curnode next the item has to be in the bag to remove it assert curnode is not none"the item must be in the bag unlink the node and return the item self _size - if curnode is head self _head curnode next else prednode next curnode next return curnode item returns an iterator for traversing the list of items def __iter__self )return _bagiteratorself _head defines private storage class for creating list nodes class _baglistnodeobject )def __init__selfitem self item item self next none