the bag abstract data type there are several variations of the bag adt with the one described here being simple bag grab bag is similar to the simple bag but the items are removed from the bag at random another common variation is the counting bagwhich includes an operation that returns the number of occurrences in the bag of given item implementations of the grab bag and counting bag are left as exercises define bag adt bag is container that stores collection in which duplicate values are allowed the itemseach of which is individually storedhave no particular order but they must be comparable bag()creates bag that is initially empty length ()returns the number of items stored in the bag accessed using the len(function contains item )determines if the given target item is stored in the bag and returns the appropriate boolean value accessed using the in operator additem )adds the given item to the bag removeitem )removes and returns an occurrence of item from the bag an exception is raised if the element is not in the bag iterator ()creates and returns an iterator that can be used to iterate over the collection of items you may have noticed our definition of the bag adt does not include an operation to convert the container to string we could include such an operationbut creating string for large collection is time consuming and requires large amount of memory such an operation can be beneficial when debugging program that uses an instance of the bag adt thusit' not uncommon to include the str operator method for debugging purposesbut it would not typically be used in production software we will usually omit the inclusion of str operator method in the definition of our abstract data typesexcept in those cases where it' meaningfulbut you may want to include one temporarily for debugging purposes examples given the abstract definition of the bag adtwe can create and use bag without knowing how it is actually implemented consider the following simple examplewhich creates bag and asks the user to guess one of the values it contains