new set union the efficiency of the set union operation can also be improved from the original version set union using two sorted lists is very similar to the problem of merging two sorted lists that was introduced in the previous section in that problemthe entire contents of the two sorted lists were merged into third list for the set adt implemented using sorted listthe result of the set union must be new sorted list merged from the unique values contained in the sorted lists used to implement the two source sets the implementation of the new union(methodwhich is provided in listing uses modified version of the mergesortedlists(function the only modification required is the inclusion of an additional test within the first loop to catch any duplicate values by advancing both index variables and only appending one copy to the new sorted list the new implementation only requires (ntime since that is the time required to merge two sorted lists and the new test for duplicates does not increase that complexity the set difference and set intersection operations can also be modified in similar fashion and are left as an exercise listing new implementation of the set union method class set def unionselfsetb )newset set( merge the two lists together until one is empty while lenself and lensetb valuea self _theelements[avalueb setb _theelements[bif valuea valueb newset _theelements appendvaluea + elif valuea valueb newset _theelements appendvalueb + else only one of the two duplicates are appended newset _theelements appendvaluea + + if lista contains more itemsappend them to newlist while lenself newset _theelements appendself _theelements[aa + or if listb contains moreappend them to newlist while lenotherset newset _theelements appendsetb _theelements[bb + return newset