<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def replace(self, old, new):
 """ Replace all lines of file that match 'old' with 'new' Will replace duplicates if found. :param old: String, List of Strings, a multi-line String, or False; what to replace. :param new: String; what to use as replacement. :return: Boolean; whether contents changed during method call. """

        self.log('replace({0}, {1})'.format(old, new))
        if old is False:
            return False
        if isinstance(old, str):
            old = old.split('\n')
        if not isinstance(old, list):
            raise TypeError("Parameter 'old' not a 'string' or 'list', is {0}".format(type(old)))
        if not isinstance(new, str):
            raise TypeError("Parameter 'new' not a 'string', is {0}".format(type(new)))
        local_changes = False
        for this in old:
            if this in self.contents:
                while this in self.contents:
                    index = self.contents.index(this)
                    self.changed = local_changes = True
                    self.contents.remove(this)
                    self.contents.insert(index, new)
                    self.log('Replaced "{0}" with "{1}" at line {2}'.format(this, new, index))
            else:
                self.log('"{0}" not in {1}'.format(this, self.filename))
        return local_changes