mathematical intersection (there may be duplicates in the result)and isn' required at all (as we've seenpython' set data type provides built-in intersection operationindeedthe function could be replaced with single list comprehension expressionas it exhibits the classic loop collector code pattern[ for in if in [' '' '' 'as function basics examplethoughit does the job--this single piece of code can apply to an entire range of object typesas the next section explains in factwe'll improve and extend this to support arbitrarily many operands in after we learn more about argument passing modes polymorphism revisited like all good functions in pythonintersect is polymorphic that isit works on arbitrary typesas long as they support the expected object interfacex intersect([ ]( ) [ mixed types saved result object this timewe passed in different types of objects to our function-- list and tuple (mixed types)--and it still picked out the common items because you don' have to specify the types of arguments ahead of timethe intersect function happily iterates through any kind of sequence objects you send itas long as they support the expected interfaces for intersectthis means that the first argument has to support the for loopand the second has to support the in membership test any two such objects will workregardless of their specific types--that includes physically stored sequences like strings and listsall the iterable objects we met in including files and dictionariesand even any class-based objects we code that apply operator overloading techniques we'll discuss later in the book here againif we pass in objects that do not support these interfaces ( numbers)python will automatically detect the mismatch and raise an exception for us--which is exactly what we wantand the best we could do on our own if we coded explicit type this code will always work if we intersect filescontents obtained with file readlines(it may not work to intersect lines in open input files directlythoughdepending on the file object' implementation of the in operator or general iteration files must generally be rewound ( with file seek( or another openafter they have been read to end-of-file onceand so are single-pass iterators as we'll see in when we study operator overloadingobjects implement the in operator either by providing the specific __contains__ method or by supporting the general iteration protocol with the __iter__ or older __getitem__ methodsclasses can code these methods arbitrarily to define what iteration means for their data function basics