{'eggs''ham''spam'plus there are additional operations we won' illuminate here--see core language text such as learning python for more details for instancebuilt-in sets also support operations such as superset testingand they come in two flavorsmutable and frozen (frozen sets are hashableand thus usable in sets of setsmoreoverset comprehensions are more powerful than suggestedand sets are natural at duplicate removaly { upper( for in 'spamham' {'ssss''aaaa''mmmm''hhhh''pppp'list(set([ ])[ set comprehension remove duplicates from list as for stacksthoughthe built-in set type might not by itself achieve all our goals moreoverhomegrown set implementations turn out to be an ideal vehicle for studying custom data structure implementations in python although the end result may not compete with the performance of built-in set objects todaythe code can still be instructive to readand fun to experiment with also as for stacksa custom set implementation will generally be based upon other built-in types python liststuplesand strings come close to the notion of setthe in operator tests membershipfor iteratesand so on herewe'll add operations not directly supported by python sequences in effectwe're extending built-in types for unique requirements set functions as beforelet' first start out with function-based set manager but this timeinstead of managing shared set object in modulelet' define functions to implement set operations on passed-in python sequences (see example - example - pp \dstruct\basic\inter py "set operations for two sequencesdef intersect(seq seq )res [for in seq if in seq res append(xreturn res def union(seq seq )res list(seq for in seq if not in resstart with an empty list scan the first sequence add common items to the end make copy of seq add new items in seq implementing sets