<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def insert(self, thread):
 """Process a thread and insert its comments in the DB."""

        thread_id = thread['id']
        title = thread['title']
        self.db.threads.new(thread_id, title)

        comments = list(map(self._build_comment, thread['comments']))
        comments.sort(key=lambda comment: comment['id'])
        self.count += len(comments)
        for comment in comments:
            self.db.comments.add(thread_id, comment)