def difference(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 self<EOL><DEDENT>if self.meta_type == '<STR_LIT:list>':<EOL><INDENT>keep = []<EOL>for item in self._list:<EOL><INDENT>if item not in other._list:<EOL><INDENT>if recursive and isinstance(item, composite):<EOL><INDENT>keep.extend(item.difference(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.difference(other.get(key), recursive=True)<EOL><DEDENT>elif item != other[key]:<EOL><INDENT>keep[key] = item<EOL><DEDENT><DEDENT>else:<EOL><INDENT>keep[key] = item<EOL><DEDENT><DEDENT>return composite(keep)<EOL><DEDENT>return<EOL>
Recursively compute difference of data. For dictionaries, items
for specific keys will be reduced to differences. For lists, items
will be reduced to differences. This method is meant to be analogous
to set.difference for composite objects.

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