def intersection(self, other, recursive=True):
if not isinstance(other, composite):<EOL><INDENT>raise AssertionError('<STR_LIT>'.format(type(other)))<EOL><DEDENT>if self.meta_type != other.meta_type:<EOL><INDENT>return composite({})<EOL><DEDENT>if self.meta_type == '<STR_LIT:list>':<EOL><INDENT>keep = []<EOL>for item in self._list:<EOL><INDENT>if item in other._list:<EOL><INDENT>if recursive and isinstance(item, composite):<EOL><INDENT>keep.extend(item.intersection(other.index(item), recursive=True))<EOL><DEDENT>else:<EOL><INDENT>keep.append(item)<EOL><DEDENT><DEDENT><DEDENT>return composite(keep)<EOL><DEDENT>elif self.meta_type == '<STR_LIT>':<EOL><INDENT>keep = {}<EOL>for key in self._dict:<EOL><INDENT>item = self._dict[key]<EOL>if key in other._dict:<EOL><INDENT>if recursive andisinstance(item, composite) andisinstance(other.get(key), composite):<EOL><INDENT>keep[key] = item.intersection(other.get(key), recursive=True)<EOL><DEDENT>elif item == other[key]:<EOL><INDENT>keep[key] = item<EOL><DEDENT><DEDENT><DEDENT>return composite(keep)<EOL><DEDENT>return<EOL>
Recursively compute intersection of data. For dictionaries, items
for specific keys will be reduced to unique items. For lists, items
will be reduced to unique items. This method is meant to be analogous
to set.intersection for composite objects.

Args:
    other (composite): Other composite object to intersect with.
    recursive (bool): Whether or not to perform the operation recursively,
        for all nested composite objects.