<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_statements(self, statements):
 """Insert the statements into the file neatly. Ex: statements = ["good 'dog'", "good 'cat'", "bad 'rat'", "fat 'emu'"] good 'cow' nice 'man' bad 'news' animals.write_statements(statements) # stream.txt good 'cow' good 'dog' good 'cat' nice 'man' bad 'news' bad 'rat' fat 'emu' """

        self.seek(0)
        original_content_lines = self.readlines()
        new_content_lines = copy.copy(original_content_lines)
        # ignore blanks and sort statements to be written
        statements = sorted([stmnt for stmnt in statements if stmnt])

        # find all the insert points for each statement
        uniqs = {stmnt.split(None, 1)[0] for stmnt in statements}
        insert_locations = {}
        for line in reversed(original_content_lines):
            if not uniqs:
                break
            if not line:
                continue
            for word in uniqs.copy():
                if line.startswith(word):
                    index = original_content_lines.index(line) + 1
                    insert_locations[word] = index
                    uniqs.remove(word)

        for statement in statements:
            print("writing to %s : %s" % (self, statement))
            startswith = statement.split(None, 1)[0]
            # insert new statement with similar OR at the end of the file
            new_content_lines.insert(
                insert_locations.get(startswith, len(new_content_lines)),
                statement)

        if new_content_lines != original_content_lines:
            self.seek(0)
            self.writelines(new_content_lines)
            self.flush()